
To prevent unwanted uploads, I added a Upload button for each file in the queue. Clicking the first button starts uploading the specific file, but unfortunately, after completing the upload, it automatically starts with the next file. How could I prevent this? (I don't want automatic uploading because I need to check if a necessary variable (addPostParam) is actually there).
An alternative approach could be using 2 different queues: one for selected files, and one for the files that were confirmed.
One at a time by default
SWFUpload v2 does not autoupload the next file by default. So, you are either using the Queue plugin which does this or you have code in your uploadComplete handler that is uploading the next file.
You either need to stop using the Queue plugin, modify the queue plugin (starting at line 50) or fix your uploadComplete handler.
Thanks
Thanks gyphie for your prompt reply. I am working with the multiinstancedemo and just realized the swfupload.queue.js file is not even used in the example although it's being linked to
.
I already managed to send a addPostParam with each file. What I'd like to do is only slightly different, but imho it is more user friendly when handling lots of files:
1) Select some files.
2) A file in the queue can be connected with a database id.
3) Only after a manual confirmation the file will come in the 'upload queue', waiting for upload.
While the upload process is busy, files can be deleted from the queue, and at the same time new files can be added.
The difference is that the variables are added after the file is being queued. So, is there a way to add 1 or 2 variables (id + confirmation flag) to a file after it's being queued, and check for this when the uploading process has reached that file, or does this imply changes in the .swf file?
File Object ID
If you are linking to the Queue plugin then it is automatically being used.
What you want to do is supported by SWFUpload. Every SWFUpload event that relates to a file (i.e., every event excecpt fileDialogStart, fileDialogComplete) receives a file object as a parameter.
The File Object holds an ID property that is used to reference the file in order to trigger uploads or add Post params for that file.
Here is some pseudo code. Notice I need to have the File ID in order to assign the database id and confirmation code to the SWFUpload file:
function doValidation(file_id, some_other_info) {
if (some_other_info == some_value) {
var confirmation_code = getConfirmationCode();
var database_id = getDatabaseID();
swfu.addFileParam(file_id, "confirmation_code", confirmation_code);
swfu.addFileParam(file_id, "database_id", database_id);
} else {
alert("your file is no good");
}
}
If you called doValidation from the fileQueued event it might look like this:
function fileQueued(file) {
doValidation(file.id);
}
You will have to do something similar when you create the upload button for this file. After you've created the button you need to assign the onclick handler to something like this:
function createButton(file_id) {
var uploadButton = createNewButton();
uploadButton.click = function () {
swfu.startUpload(file_id);
};
}
Wow!
Thanks again! I'll try this immediately.
This partly works
This works but only for one file at a time: when the uploadButton for the first file is clicked, the file is uploaded right away. But when a second file is confirmed as well, it's not uploaded after the first upload is finished. So the second 'click' is forgotten.
It does work when I click the button after the first upload is finished. How could I set a confirmation flag so it gets uploaded as soon as the previous upload is finished?
One at a time
Currently SWFUpload only uploads 1 file at a time. Some testing is being done to see if we can upload multiple files simultaneously and (if so) will be part of SWFUpload v3.
The only way around this is to use multiple separate instances of SWFUpload (1 flash movie/SWFUpload object per uploading file). It's possible, but tricky and might have a negative effect on browser speed and memory usage. I've heard of some people doing this but haven't heard back on how it performs.
Another issue with using separate instances is that you have to call selectFiles separately on each instance and that pretty much breaks the multiple selection feature (most people don't expect to be able to select multiple files in a browser's upload dialog anyways so it might not matter).
No
Gyphie, I think you misunderstood. I'm fully satisfied with uploads one after each other.
However, your solution is not working like expected. What's happening is:
0) select files
1) confirm file 1 for upload --> upload starts
2) confirm file 2 --> but is not uploaded after upload 1 is finished (confirmation is forgotten)
File 2 is uploaded only when the confirmation is done after upload of file 1 is finished.
The goal is:
0) select files
1) confirm file 1 for upload --> upload starts
2) confirm file 2 for upload --> as soon as upload 1 is finished file 2 will be uploaded
3) confirm file 3 for upload --> waiting in line until upload 2 is finished
4) file 4 not confirmed (yet) --> waiting for confirmation
5) file 5 not confirmed (yet) --> waiting for confirmation
6) confirm file 6 for upload --> waiting in line until upload 3 is finished
So exactly like the multiupload is working now, except for the confirmation thing.
Ahh
If I were doing something like that I'd probably keep an array of all the queued files and their confirmation status.
In uploadComplete I'd get the first confirmed file from the array and start the upload for that file. I'd also either mark the file as complete or remove the file reference from the array of the file that just completed.
In uploadError I'd make sure I handled the error as needed (removing the file from the "confirmation" array so it doesn't get uploaded again.
Then on the confirmation button I'd have code to add the file id to confirmation array and you'd probably have to have it check to see if a file is currently uploading and, if not, start the upload.
Yes
This sounds so logical, why didn't I think of this?
It works perfect. Thanks for helping me out.