Finish of Multiple file upload

為{幸葍}努か 提交于 2019-12-04 03:03:44

问题


I have a question about the use of Blueimp jQuery-File-Upload plugin (https://github.com/blueimp/jQuery-File-Upload)

There is a callback function or an alternative method, to know when is finished an upload of multiple files? I do not want to know when is finished the upload of every single file, but when is finished the entire process (All Uploads Complited).

There is also the opportunity to know how many files have actually been loaded and how many they were requested?


回答1:


Please have a look at the "stop" callback option:

.bind('fileuploadstop', function (e) {/* ... */})

And If you want to track uploaded files try to use this:

$('#fileupload').bind('fileuploaddone', function (e, data) { }

Your collections data.files only contain 1 object each, hence you can track the count of files been uploaded.




回答2:


Yes, you can call it API to track the end of a multiple upload process:

var $fileInput = $('#fileupload');

$fileInput.on('fileuploaddone', function(e, data) {
    var activeUploads = $fileInput.fileupload('active');
    /*
     * activeUploads starts from the max number of files you are uploading to 1 when the last file has been uploaded.
     * All you have to do is doing a test on it value.
     */
    if(activeUploads == 1) {
        console.info("All uploads done");
        // Your stuff here
    }
}



回答3:


Just on this guys, you can get the number of active uploads using the below:

var activeUploads = $('#fileuploadForm').fileupload('active');

See: https://github.com/blueimp/jQuery-File-Upload/wiki/API#retrieving-the-number-of-active-uploads

I was going to use a counter on always callback function to compare to this variable. But stop looks like it works perfectly.

Just want to clarify. If i have multiple singular file upload requests is stop() the best approach?



来源:https://stackoverflow.com/questions/19025748/finish-of-multiple-file-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!