【发布时间】:2015-04-08 17:32:02
【问题描述】:
我有一个文件上传表单,它使用 Dropzone.js 将文件上传到我的服务器。用户一次最多可以上传 5 个文件,但我正在处理一个独特的情况:如果服务器端出现任何单个文件错误(超过最大大小、错误的 mime 类型、错误的文件类型等) ,我不需要将任何文件添加到我的数据库中。这不是问题。
我遇到的问题是客户端处理它。为什么当我收到服务器的响应时,我无法再通过单击“提交”(其元素绑定到事件处理程序,如下所示)再次上传文件?
Dropzone.options.uploadedFilesDropzone = {
autoProcessQueue: false,
maxFilesize: 1024, //MB
addRemoveLinks: true,
uploadMultiple: true,
parallelUploads: 5,
maxFiles: 5,
init: function() {
var uploadedFilesDropzone = this;
$('#submit').on('click', function() {
uploadedFilesDropzone.processQueue();
uploadedFilesDropzone.on("successmultiple", function(files, response) {
// Handle the responseText here. For example, add the text to the preview element:
console.log(files);
console.log(response.errors[0]);
$.each(files, function(index, file) {
// no errors
if (response.errors[index].length == 0) {
} else {
file.previewElement.classList.add('dz-error');
}
})
});
});
}
}
【问题讨论】:
-
点击提交失败是什么情况?什么都没有发生?你有错误吗?如果没有错误,你能上传更多吗?
-
这个保管箱问题可能会有所帮助,github.com/enyo/dropzone/issues/717
标签: javascript file-upload dropzone.js