Topic: How to detect when all potential files have been processed by plupload

I've set a file size limit of 10 MB with a plupload instance and I'd like to generate a single error message for any files being too large when a user selects multiple files.

I know I can generate an error for each oversized file individually, but I need to prompt the user with an alert and if they select many oversized files they would end up with a whole bunch of alerts popping up one after the other.  So the solution seems to be to collect any oversized files that were selected and then report the errors one time after plupload is done processing potential files.

This seems to be a bit tricky.  I've half solve the problem but can't figure out a way to deal with all cases.  Consider these two use cases:

1. The user selects a number of files of which a subset are oversized.  Each oversized file can be added to an array by code in my 'Error' callback.  Then when the 'FilesAdded' callback is called I can check the length of the oversized files array and report that some of the files were too large and will not be uploaded.  So I've taken care of this case.

2. The user selects one or more files and they are all oversized.  In this case I can add each of the files to the oversized files array, but I can't seem to find a way to determine when plupload is done processing the potential files.  The 'FilesAdded' callback never gets called as no files are actually added to the queue.  Similarly the 'QueueChanged' callback does not get called.  So I haven't been able to solve the problem for this use case.

So are there any publicly visible properties I can observe from within the 'Error' callback to determine when the last potential file has been processed from a user's selection?

I hope I've explained the problem clearly.  Any help is appreciated.

Mike

Re: How to detect when all potential files have been processed by plupload

For such cases you might bind to FilesAdded event, before you call uploader.init(). Actually if you do this and return false from the callback, default handler will never be called. You might need to be careful, since if you manipulate files array directly, that will be what a default callback will get after you.

If you want to see your issue fixed, do not report it here, do it on - GitHub.

Re: How to detect when all potential files have been processed by plupload

Thanks davit,

This worked well.  For others with the same problem here is a more complete description of what I did in code (well close enough to code at least):

overSizedFiles = [];
numberOfFilesSelected = 0;

var pluploader = new plupload.Uploader({
    runtimes : 'html5,flash,html4',
    .... 
});

pluploader.bind('FilesAdded', function(up, files)
{
    numberOfFilesSelected = files.length;
    return true;
});

pluploader.init;

pluploader.bind('Error', function(up, err)
{
    up.refresh();

    if(err.code === plupload.FILE_SIZE_ERROR)
    {
        overSizedFiles.push(err.file.name);

        if(overSizedFiles.length === numberOfFilesSelected)
        {
            alert("These Files are too large and will not be uploaded: " + 
                    overSizedFiles.join(", "));
            overSizedFiles = [];
            numberOfFilesSelected = 0;
        }
    }
    else
    {
        // Notify about other types of errors here.
    }
});

pluploader.bind('FilesAdded', function(up, files)
{
    if(overSizedFiles.length !== 0)
    {
        alert("These Files are too large and will not be uploaded: " + 
                overSizedFiles.join(", "));
        overSizedFiles = [];
        numberOfFilesSelected = 0;
    }

    ....
});

Thanks again.