dropzone.js - how to do something after ALL files are uploaded

后端 未结 9 1186
花落未央
花落未央 2020-12-13 05:48

I am using dropzone.js for my drag-drop file upload solution. I am stuck at something where I need to call a function after all the files are uploaded. In this case

9条回答
  •  盖世英雄少女心
    2020-12-13 06:31

    In addition to @enyo's answer in checking for files that are still uploading or in the queue, I also created a new function in dropzone.js to check for any files in an ERROR state (ie bad file type, size, etc).

    Dropzone.prototype.getErroredFiles = function () {
        var file, _i, _len, _ref, _results;
        _ref = this.files;
        _results = [];
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
            file = _ref[_i];
            if (file.status === Dropzone.ERROR) {
                _results.push(file);
            }
        }
        return _results;
    };
    

    And thus, the check would become:

      if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0 && this.getErroredFiles().length === 0) {
        doSomething();
      }
    

提交回复
热议问题