javascript Dropzone 最大文件大小超出事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29161017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dropzone max file size exceeded event
提问by AVM
I am using dropzone in my form for image upload. I would like to show an alert message and remove the file added when the user chooses a file above the configured limit. Here is my configuration:
我在表单中使用 dropzone 进行图像上传。当用户选择超出配置限制的文件时,我想显示一条警报消息并删除添加的文件。这是我的配置:
Dropzone.options.myDropzone = {
paramName: 'file',
url: "http://someurl",
clickable: true,
enqueueForUpload: true,
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 5,
maxFiles: 1,
maxFilesize: .06,
maxThumbnailFilesize: .06,
acceptedMimeTypes: 'image/*',
addRemoveLinks: true,
dictDefaultMessage: 'Drag your images here',
init: function() {
console.log('init');
this.on("maxfilesexceeded", function(file){
alert("No more files please!");
this.removeFile(file);
});
}
};
I tried to register a listener for 'maxfilesizeexceeded' event, but it didnt fire. I would like to take similar action as for 'maxfilesexceeded'. Is this possible?
我试图为 'maxfilesizeexceeded' 事件注册一个监听器,但它没有触发。我想对“maxfilesexceeded”采取类似的行动。这可能吗?
回答by Luka
I have just tried it out on my script using the Error event. This way I get an Error Message and the File gets removed again. Is this what you are looking for?
我刚刚使用 Error 事件在我的脚本上进行了尝试。这样我会收到一条错误消息,并且文件再次被删除。这是你想要的?
this.on("error", function(file, message) {
alert(message);
this.removeFile(file);
});