【问题标题】:How to reupload after fail using dropzone?使用dropzone失败后如何重新上传?
【发布时间】:2016-03-03 02:36:53
【问题描述】:

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

所以我在 dropzone 中选择了一张图片并点击上传(我使用的是autoProcessQueue:false

并假设上传失败。图片上方会有一个错误标记。

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

这是一个错误吗?失败后如何重新上传图片?

【问题讨论】:

    标签: node.js dropzone.js


    【解决方案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);
    
        }
    });
    

    【讨论】:

    • 四年半后,它适用于 dropzone 5.0。谢谢!
    【解决方案2】:

    将其设置为 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

    【讨论】:

    • Dropzone.QUEUED 正在使用 5.7.0 版
    猜你喜欢
    • 2015-04-08
    • 2019-02-21
    • 1970-01-01
    • 2018-03-04
    • 2016-02-18
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    • 2016-09-14
    相关资源
    最近更新 更多