views:

21

answers:

2

I'm using the YUI 2 Uploader to upload some files. My users will be uploading more than one file, so I want to use YUI Uploader's 'file queue'. That is all working successfully. I disable the uploader when the files are uploading, so people can't add new files to the queue once they start uploading the files.

I want to do something (in JavaScript) when all the files have been uploaded. The YUI Uploader has signals for when certain files are uploaded, but not when all files in the queue have been uploaded. Is there some way to detect when all the files have been uploaded?

A: 

Create an eventhandler for the uploadcomplete event. Take a look at the yui uploader documentation: http://developer.yahoo.com/yui/docs/YAHOO.widget.Uploader.html

http://developer.yahoo.com/yui/examples/uploader/uploader-advanced-queue.html

function onUploadComplete(event) {
        rowNum = fileIdHash[event["id"]];
        prog = Math.round(100*(event["bytesLoaded"]/event["bytesTotal"]));
        progbar = "<div style='height:5px;width:100px;background-color:#CCC;'><div style='height:5px;background-color:#F00;width:100px;'></div></div>";
        singleSelectDataTable.updateRow(rowNum, {name: dataArr[rowNum]["name"], size: dataArr[rowNum]["size"], progress: progbar});
    }
Bruce Adams
That is called once per file when that file is uploaded. If there are 3 items in the queue, then this method is called when the first one is finished. I want something that is only called when all 3 have been uploiaded.
Rory
+1  A: 

Keep an object (or array) of files & in the uploadComplete handler remove whichever file just finished. If there are none left call your upload finalize function.

Example implementation here, http://tivac.com/upload/upload.js It has some bugs but solves this particular problem.

Tivac