Sorting queued files before upload

Hi,

First, thanks for SWFUpload. What a great contribution.

My question: Is it possible to sort queued files before upload? I have a requirement that files must be uploaded in alphabetical order. Current behavior seems to be somewhat random as to how files are ordered when multi-selecting files.

Thanks for your help.
--Erik

Re sorting

Related thread with replies.
http://swfupload.org/forum/generaldiscussion/417

I'll see if I can set aside a little time to look at and write the code to sort files that are queued.

Attempt at sorting

Hi,

I attempted to solve this myself. I started with the SWFObject Plugin Demo.

I added the following to the top of handlers.js to override some functionality in both swfupload.js AND swfupload.queue.js.

What I found is that in the call to startUpload(fileID), the 'fileID' parameter is ignored and that the files are being uploaded in the original default order, rather than the order I'm attempting to specify.

Sorry about the formatting. It seems to be ignoring leading spaces.


var SWFUpload;
if (typeof(SWFUpload) === "function") {
SWFUpload.ordered = new Array();

SWFUpload.prototype.orderFiles = function() {
var stats = this.getStats();
var numFiles = stats.files_queued;
for (i=0; i<numFiles; i++) {
var file = this.getFile(i);
file.toString = function() { return this.name.toLowerCase(); }
SWFUpload.ordered.push(file);
}
SWFUpload.ordered.sort();
SWFUpload.ordered.reverse(); // reversed to make it FIFO.
};

SWFUpload.prototype.nextFile = function() {
return SWFUpload.ordered.pop();
};

SWFUpload.queue.uploadCompleteHandler = function (file) {
var user_upload_complete_handler = this.settings.user_upload_complete_handler;
var continueUpload;

if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
this.customSettings.queue_upload_count++;
}

if (typeof(user_upload_complete_handler) === "function") {
continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
} else {
continueUpload = true;
}

if (continueUpload) {
var stats = this.getStats();
if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) {
var file = this.nextFile();
alert(file.name);
this.startUpload(file.id);
} else if (this.customSettings.queue_cancelled_flag === false) {
this.queueEvent("queue_complete_handler", [this.customSettings.queue_upload_count]);
this.customSettings.queue_upload_count = 0;
} else {
this.customSettings.queue_cancelled_flag = false;
this.customSettings.queue_upload_count = 0;
}
}
};
}

I also modified the following existing method from handlers.js like so:


function fileDialogComplete(numFilesSelected, numFilesQueued) {

try {

if (numFilesSelected > 0) {
document.getElementById(this.customSettings.cancelButtonId).disabled = false;
}
/* I want auto start the upload and I can do that here */
this.orderFiles();
var file = this.nextFile();
alert(file.name);
this.startUpload(file.id);
} catch (ex) {
this.debug(ex);
}
}