url encoding scriptdata values

Help!! It's not working for me. How can I???

url encoding scriptdata values

Postby davekaro » Sat Jul 25, 2009 9:13 pm

Hello all,

I am trying to pass an authenticity_token as part of the scriptData option to the uploadify function (using the brand new 2.0 release). So, this is the javascript I end up with

Code: Select all
$(document).ready(function(){
$('#uploadify').uploadify({
'uploader' : '/flash/uploadify.swf',
'script' : '/asset',
'cancelImg' : '/images/cancel.png',
'fileDataName' : 'asset[asset]',
'scriptData' : {
   'authenticity_token' : 'R4%2BOZiOjf8XoHDzkPM1rY7yKb%2B1QUnM6XUPfS7GU2r0%3D'
},
'auto' : true,
'multi' : true,
'fileExt' : '*.jpg;*.pdf;*.eps;*.tiff'
});
});


Notice that the authenticity_token is already url encoded. So, the %2B and the %3D are + and = symbols. However, what I see on my server side after trying to upload a file is:

Code: Select all
"authenticity_token"=>"R4 OZiOjf8XoHDzkPM1rY7yKb 1QUnM6XUPfS7GU2r0="


The + signs are now spaces. Any ideas?
davekaro
 
Posts: 3
Joined: Sat Jul 25, 2009 8:59 pm

Re: url encoding scriptdata values

Postby TravisN. » Sun Jul 26, 2009 1:02 am

There is something fishy happening when flash converts the scriptData to URLVariables. scriptData now works when variables include spaces. Admittedly I didn't test it with + symbols. Even using enocdeURIComponents() doesn't seem to make any difference. We'll need to take a closer look at this. For the moment you can base64 encode your token for passing through to the upload script. Just decode it in the script
Uploadify - where simplify and upload meet

Travis Nickels
Uploadify Developer
TravisN.
 
Posts: 656
Joined: Sat Mar 07, 2009 12:34 am
Location: Australia

Re: url encoding scriptdata values

Postby davekaro » Sun Jul 26, 2009 5:11 am

Thanks for the reply, Travis.

FWIW, I did get this to work. I had to use this is my application though:

Code: Select all
        'scriptData'    : {
            'authenticity_token'        : encodeURIComponent('R4%2BOZiOjf8XoHDzkPM1rY7yKb%2B1QUnM6XUPfS7GU2r0%3D')
        },


Notice the string I'm passing to encodeURIComponent is already URL encoded. If I do not first URL encode this string, it fails.
So, for whatever reason, I have to pass an already URL encoded string to encodeURIComponent to get it to work.

Admittedly, I'm not sure if this has to do with my environment or strictly uploadify. I may do some more testing tomorrow to narrow down variables.

Thanks!
Dave
davekaro
 
Posts: 3
Joined: Sat Jul 25, 2009 8:59 pm

Re: url encoding scriptdata values

Postby daveznspace » Fri Aug 07, 2009 10:00 am

you should encode them first and you can always decode them after
daveznspace
 
Posts: 86
Joined: Tue Mar 17, 2009 2:34 am


Return to Implementation Help

Who is online

Users browsing this forum: Google [Bot], mojitoo and 9 guests