使用 dropzone 失败后如何重新上传?
How to reupload after fail using dropzone?
我正在使用 dropzone 上传文件,我发现了一个问题。
所以我通过拖放区选择了一张图片并点击上传(我正在使用autoProcessQueue:false
)
假设上传失败。图片上方会有错误标记。
然后我再次点击上传。通过查看开发人员工具栏,我看到 formdata.files 是空的。没有文件正在上传到服务器。
这是一个错误吗?图片失败后如何重新上传?
代码取自 https://github.com/enyo/dropzone/issues/617。问题出在错误上,file.status 没有更新为 Dropzone.QUEUED.
view.dropzone = new Dropzone(form[0], {
...
autoProcessQueue: false,
uploadMultiple: false,
parallelUploads: 100,
maxFiles: 1,
thumbnailWidth: 300,
thumbnailHeight: null,
previewsContainer: inputPreview[0],
clickable: inputClick[0],
acceptedFiles: 'image/*',
...
error: function(file, errorMessage, xhr) {
// Trigger an error on submit
view.onSubmitComplete({
file: file,
xhr: xhr
});
// Allow file to be reuploaded !
file.status = Dropzone.QUEUED;
// this.cancelUpload(file);
// this.disable();
// this.uploadFile(file);
}
});
将其设置为 Dropzone.QUEUED
不再有效。如果查看源代码:
enqueueFile(file) {
if ((file.status === Dropzone.ADDED) && (file.accepted === true)) {
file.status = Dropzone.QUEUED;
if (this.options.autoProcessQueue) {
return setTimeout((() => this.processQueue()), 0); // Deferring the call
}
所以这是我为让它工作所做的(重新上传):
file.status = Dropzone.ADDED
dropzone.enqueueFile(file)
假设 file.accepted
是 true
并且 autoProcessQueue
设置为 true
我正在使用 dropzone 上传文件,我发现了一个问题。
所以我通过拖放区选择了一张图片并点击上传(我正在使用autoProcessQueue:false
)
假设上传失败。图片上方会有错误标记。
然后我再次点击上传。通过查看开发人员工具栏,我看到 formdata.files 是空的。没有文件正在上传到服务器。
这是一个错误吗?图片失败后如何重新上传?
代码取自 https://github.com/enyo/dropzone/issues/617。问题出在错误上,file.status 没有更新为 Dropzone.QUEUED.
view.dropzone = new Dropzone(form[0], {
...
autoProcessQueue: false,
uploadMultiple: false,
parallelUploads: 100,
maxFiles: 1,
thumbnailWidth: 300,
thumbnailHeight: null,
previewsContainer: inputPreview[0],
clickable: inputClick[0],
acceptedFiles: 'image/*',
...
error: function(file, errorMessage, xhr) {
// Trigger an error on submit
view.onSubmitComplete({
file: file,
xhr: xhr
});
// Allow file to be reuploaded !
file.status = Dropzone.QUEUED;
// this.cancelUpload(file);
// this.disable();
// this.uploadFile(file);
}
});
将其设置为 Dropzone.QUEUED
不再有效。如果查看源代码:
enqueueFile(file) {
if ((file.status === Dropzone.ADDED) && (file.accepted === true)) {
file.status = Dropzone.QUEUED;
if (this.options.autoProcessQueue) {
return setTimeout((() => this.processQueue()), 0); // Deferring the call
}
所以这是我为让它工作所做的(重新上传):
file.status = Dropzone.ADDED
dropzone.enqueueFile(file)
假设 file.accepted
是 true
并且 autoProcessQueue
设置为 true