简体   繁体   English

确定何时在dropzone.js中成功上传了所有文件

[英]Determine when all files have uploaded successfully in dropzone.js

I'm using dropzone.js to upload to my website. 我正在使用dropzone.js上传到我的网站。 The uploader is in a modal, which I want to automatically close when all files have been uploaded successfully. 上传器处于模式,我想在所有文件成功上传后自动关闭。

To do this I am using the following code: 为此,我使用以下代码:

buttonUpload.on("complete", function (file) {

    var remaining = buttonUpload.getRejectedFiles().length + buttonUpload.getQueuedFiles().length + buttonUpload.getUploadingFiles().length

    if (remaining == 0) {
        $("#modal-upload-file").modal('hide');
    }
});

I would expect this code to add together the number of files that have failed, have not yet uploaded and are uploading. 我希望这段代码将失败,尚未上传和正在上传的文件数量加在一起。 If this is zero, then the modal closes. 如果为零,则模态关闭。

I was able to determine that buttonUpload.getRejectedFiles() does not include files that received an error when uploading. 我能够确定buttonUpload.getRejectedFiles()不包含上载时收到错误的文件。 From reading the documentation, I can see no way of checking if every file has uploaded successfully like I want to. 通过阅读文档,我看不到检查每个文件是否都按我的意愿成功上传的方法。 How can I do this? 我怎样才能做到这一点?

Here's my solution. 这是我的解决方案。

On success, the file is removed from the queue: 成功后,将从队列中删除文件:

buttonUpload.on("success", function(file) {
    buttonUpload.removeFile(file);
});

Then, when the queue is completed, if any files remain they were not successful. 然后,当队列完成时,如果剩余任何文件,则它们不成功。

buttonUpload.on("queuecomplete", function (file) {
    if (buttonUpload.getAcceptedFiles().length > 0) {
        $("#file-error-warning").slideDown();
    } else {
        $("#modal-upload-file").modal('hide');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM