uploadify | changing uploadifysettings on the fly
I am stuck. I am using uploadify to upload multiple files to my s3 server. I would like to put each file into a folder that has a unique identifier. What I was hoping to do was to use this syntax to accomplish that (note uuid is a jquery plugin to generate uuids):
'onComplete' : function(event,queueId,f开发者_开发百科ileObj,response) {
$('#fileInput').uploadifySettings('folder',$.uuid())
}
My issue is that when this callback gets called -- i not longer have access to $('#fileInput').uploadifySettings(x,y)
i get that it is an undefined method ?!
Other uploadify settings of note:
'auto': 'true'
'multi': 'true'
and I am uploading directly to Amazon s3
Has anyone run into this? Ideas on how to solve?
Thanks!
I solved this same problem as follows, by changing the scriptData "onSelect" so when you select a new file:
onSelect : function(){
$('#images_upload_file').uploadifySettings("scriptData", {'yourvar': yourvalue });
},
that seems to do the trick
I hope I'm not completely misunderstanding your question.
Wouldn't it be very easy to do that on the server-side? You have to handle the upload on the server-side anyway, which usually involves in some way to fetch the uploaded file from a temporary location, make sure it's not evil, and then to copy it to its final resting place.
At that last copying step, you could easily introduce a uuid (in this case generated on the server side as well, I suppose).
Would that be a valid approach, or am I missing a requirement you have?
I had the same problem. After hours of pain I finally solved it by manually manipulating the flashvars string that is passed to the flash upload object.
Given this HTML element:
<div id="file_upload" name="file_upload"></div>
I proceed to initiate uploadify on that element with this:
$('#file_upload').uploadify({
// Empty folder path
'folder' : ''
});
This adds an <object>
element with several <param>
children to your HTML-file. One of these <param>
elements is named "flashvars", and its string value contain the upload folder path. So, in order to change the folder-value, I search that string for the "folder=" argument like so:
// Find correct <param> element and retrieve it's value
var found = $("#file_uploadUploader").find("param[name=flashvars]").val();
// Search within that value for the specific folder argument using a regex
// and replace find with new_path
found = found.replace(/folder\=.*\/&/, "folder="+new_path+"&");
Hope this helps.
精彩评论