Reputation: 5113
I am using Dropzone for the uploading on MP3 and WAV files. I have set an upper limit file size of 100MB but for MP3's I want to set a limit of 15MB.
I can check the file size as soon as the add the file using the this.on("addedfile")
event listener, but I can't seem to find a way to fail the upload. I'm aware that I can remove the file from the uploader before it uploads, but I don't want to remove it, just fail with an error. How can I do this?
$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');
}
});
}
});
Upvotes: 0
Views: 3829
Reputation: 3259
I think in this case you should use the accept
instead of the addedfile
event, 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();
}
}
});
Upvotes: 2