如何使用dropzone失败后重新上传?

时间:2016-03-03 02:36:54

标签: node.js dropzone.js

我使用dropzone上传文件,我发现了一个问题。

所以我选择了一个图像trought dropzone并点击上传(我使用autoProcessQueue:false

并假设上传失败。这将是图像上方的错误标记。

然后我再次点击上传。通过观察开发人员工具栏,我看到formdata.files为空。没有文件上传到服务器。

这是一个错误吗?如何在失败后重新上载图像?

2 个答案:

答案 0 :(得分:1)

代码来自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);

    }
});

答案 1 :(得分:0)

将其设置为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.acceptedtrue,并且autoProcessQueue设置为true