我使用Dropzonejs,我想要做的事情本质上很简单。但是我找不到任何关于它的文章。Dropzonejs触发错误并取消上传
因此,在发送文件时,我们会在讨厌的.exe和.php文件上触发错误。 dropzonejs接口显示X和错误消息。所以这是正确的。问题在于,它仍然被抛入成功事件中,并被上传。
uploader.on("sending", function (file, xhr, data) {
var aDeny = [ // deny file some extensions by default
'application/x-msdownload',
'text/php'
];
if($.inArray(file.type, aDeny) !== -1) {
this.defaultOptions.error(file, 'File not allowed: ' + file.name);
return false;
}
});
Evil.exe仍然出现在这个成功事件中并被上传。响应只有一个文件路径字符串,file.status是成功的。
uploader.on('success', function (file, response) {
getData({'dostuff'});
return file.previewElement.classList.add("dz-success");
});
所以在我的“发送”事件中,如何防止文件出现在成功事件中?
更新:
谢谢!这是我需要的到底是什么:
var aDeny = [ // deny file some extensions by default
'application/x-msdownload',
'text/php'
];
Dropzone.options.uploadWidget = {
// more config...
accept: function (file, done) {
if ($.inArray(file.type, aDeny) !== -1) {
done("This file is not accepted!");
}
else {
done();
}
}
}
所以,你找到了正确的解决方案:) – codtex