PLUpload Get Files Remaining?

这一生的挚爱 提交于 2019-12-08 13:36:58

问题


So I'm using PLUpload to, well, upload files. However, I've run into a problem. I'm trying to fire an event when the queue is completed. I'm close, but not quite there. See here:

$(function() {
    var files_remaining = 0;

    // Setup flash version
    $("#flash_uploader").pluploadQueue({
        // General settings
        runtimes : 'flash',
        url : 'blah.php',
        max_file_size : '200mb',
        chunk_size : '1mb',

        // Flash settings
        flash_swf_url : 'plupload.flash.swf'
    });

    var uploader = $("#flash_uploader").pluploadQueue();

    uploader.bind('FilesAdded', function(up, file, res)
    {
        files_remaining++;
    });

    uploader.bind('FileUploaded', function(up, file, res)
    {
        files_remaining--;
        if (files_remaining == 0)
        {
            alert('Complete!');
        }
    });
});

Notice the last two .bind() uses. Basically, I'm trying to update a variable to figure out how many files have been uploaded, and then figure out (based on that) when the queue has been completed. However, as you likely know, FilesAdded isn't run on a per-file basis, but is instead run when any amount of files are added to the queue. If three files are added, FilesAdded is only called once. That means this attempt only works if one file is uploaded at a time.

So, my question is this: what is the best way to get the number of files remaining in the queue, or ultimately (even better) call an event everytime the queue finishes? I know lots of people have this problem, but I haven't found a single solution I've been able to get work!

Thanks!


回答1:


$(function() {
    var files_remaining = 0;

    // Setup flash version
    $("#flash_uploader").pluploadQueue({
        // General settings
        runtimes : 'flash',
        url : 'blah.php',
        max_file_size : '200mb',
        chunk_size : '1mb',

        // Flash settings
        flash_swf_url : 'plupload.flash.swf'
    });

    var uploader = $("#flash_uploader").pluploadQueue();

    uploader.bind('QueueChanged', function(up, files)
    {
        files_remaining = uploader.files.length;
    });

    uploader.bind('FileUploaded', function(up, file, res)
    {
        files_remaining--;
        if (files_remaining == 0)
        {
            alert('Complete!');
        }
    });
});



回答2:


In FileUploaded event check up.total.queued

uploader.bind('FileUploaded', function(up, file, res)
{
     if (up.total.queued == 0)
     {
         alert('Complete!');
     }
});


来源:https://stackoverflow.com/questions/11315855/plupload-get-files-remaining

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