【问题标题】:Cancel Upload for a single file stops the upload for all files - Dropzonejs取消单个文件的上传会停止所有文件的上传 - Dropzonejs
【发布时间】:2017-07-12 13:02:01
【问题描述】:

当我开始使用以下代码上传多个文件时,addRemoveLinks: true 提供了取消上传的选项。当我取消任何一个上传的文件时,它会停止上传所有文件。之后它还会将总进度百分比显示为 100%。

谁能帮我理解我做错了什么?我希望取消单个文件的上传不会影响其他文件的上传。 我该怎么做?

Dropzone.options.myAwesomeDropzone = { 

    autoProcessQueue: false,
    uploadMultiple: true,
    parallelUploads: 100,
    maxFiles: 100,
    maxFilesize: 1000,
    addRemoveLinks: true,
    // The setting up of the dropzone
    init: function () {
        var myDropzone = this;
        this.element.querySelector("button[type=submit]").addEventListener("click", function (e) {
            // Make sure that the form isn't actually being sent.
            e.preventDefault();
            e.stopPropagation();
            var atLeastOneIsChecked = $('input:checkbox').is(':checked');
            if(atLeastOneIsChecked)
                myDropzone.processQueue();
            else
                alert("Please select a company!");
        });

        myDropzone.on("totaluploadprogress", function (progress) {
            // Update progress bar with the value in the variable "progress", which 
            // is the % total upload progress from 0 to 100
            $("#prog").html(progress);
        });

        myDropzone.on("drop", function (event) {
            // Update progress bar with the value in the variable "progress", which 
            // is the % total upload progress from 0 to 100
            $("#prog").html("0");
        });

    }

}

【问题讨论】:

    标签: javascript jquery asp.net-mvc file-upload dropzone.js


    【解决方案1】:

    我已经通过修改源代码解决了这个问题。

    Dropzone.prototype.cancelUpload = function (file) {
        var groupedFile, groupedFiles, _i, _j, _len, _len1, _ref;
        if (file.status === Dropzone.UPLOADING) {
            this.emit("canceled", file);
        } else if ((_ref = file.status) === Dropzone.ADDED || _ref === Dropzone.QUEUED) {
            file.status = Dropzone.CANCELED;
            this.emit("canceled", file);
            if (this.options.uploadMultiple) {
                this.emit("canceledmultiple", [file]);
            }
        }
        if (this.options.autoProcessQueue) {
            return this.processQueue();
        }
    };
    

    【讨论】:

      猜你喜欢
      • 2014-05-08
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多