Hi,
I am dynamically adding some post params using addFileParam attached to the "upload_start_handler" event, the function called looks like this:
function uploadStart(file) {
this.addFileParam(file.id, "newFolder", $('new_folder_name').value);
this.addFileParam(file.id, "folder", $('folder').value);
return true;
}
The problem is that i only want to pass these params once, not for every image uploaded so i started looking at the removeFileParam function attached to the "upload_success_handler" event, my function looks like this:
function uploadSuccess(fileObj, server_data) {
try {
var progress = new FileProgress(fileObj, this.customSettings.upload_target);
progress.SetStatus("Image Saved.");
progress.ToggleCancel(false);
this.removeFileParam(fileObj.id, "newFolder");
this.removeFileParam(fileObj.id, "folder");
} catch (ex) { this.debug(ex); }
}
Unfortunately these params are not being removed, what am i doing wrong ?
November 25, 2008 - 5:56am
btw using v2.2.0 beta 3
November 25, 2008 - 10:44am
There are 2 different kinds of post parameters: File Parameters and Post Parameters.
File Parameters: These are hooked to a single file using the addFileParam function. Any parameters added using addFileParam will only be sent with that file and now others (note: your code is adding those same file params to every file right before they are uploaded).
Post Parameters: These are sent with all files uploaded. They are set using the post_parameters setting, the addPostParam function or setPostParams function. These are automatically sent with all uploaded file in addition to any File Parameters added to the individual file.
------
Your code is making File Params into something very like Post Params with the difference that if value of new_folder_name changes between uploads it will be updated on the next file (this doesn't automatically happen with post params).
If you want to attach a file param to a single specific file uploadStart is not the place to do it. You may have better luck with the fileQueued event (this depends on your application, I'm just guessing here).
November 25, 2008 - 11:30am
thanks for all the information. my handler script is not using the fileQueued event at all, any hints and tips with what i should be doing here ? Just to confirm, i have a set of values that need to be sent once per set of images uploaded, for example just with the first file.
November 25, 2008 - 12:07pm
What I'd do in that case I'd just use a flag. You can store it in the customSettings as a convenient place to hold it:
var swfu = new SWFUpload(
custom_settings: {
shouldAddParams : true
},
upload_start_handler : myUploadStart
);
function myUploadStart(file) {
if (this.customSettings.shouldAddParams) {
this.addFileParam(file.id, name, value);
this.customSettings.shouldAddParams = false;
}
}
November 26, 2008 - 4:55am
thanks man, works perfectly.