停止在Dropzone

时间:2016-01-19 14:09:32

标签: javascript dropzone.js

我正在使用Dropzone上传MP3和WAV文件。我已将上限文件大小设置为100MB,但对于MP3,我想设置15MB的限制。

我可以使用this.on("addedfile")事件监听器添加文件后立即检查文件大小,但我似乎找不到上传失败的方法。我知道我可以在上传之前从上传程序中删除该文件,但我不想删除它,只是失败并出现错误。我怎么能这样做?

$dropzone.dropzone({
            maxFilesize: 100,
            maxFiles: (limit) ? limit : 25,
            acceptedFiles: 'audio/mp3, audio/wav',
            init: function () {
                this.on("addedfile", function(file) {
                    if (file.type == 'audio/mp3' && (file.size / (1000 * 1000)) > 15) {
                        console.log('MP3 too big');
                    }
                });
            }
        });

1 个答案:

答案 0 :(得分:1)

我认为在这种情况下,您应该使用accept代替addedfile事件,http://www.dropzonejs.com/#config-accept

$dropzone.dropzone({
    maxFilesize: 100,
    maxFiles: (limit) ? limit : 25,
    acceptedFiles: 'audio/mp3, audio/wav',
    accept: function(file, done) {
        if (file.type == 'audio/mp3' && (file.size / (1000 * 1000)) > 15) {
            done('MP3 too big');
        } else {
            done();
        }
    }        
});