Posted by brandonthedeveloper at November 8th, 2007
An AIR app I’m currently working on started having problems with downloading files but only on Leopard.
Here’s what I figured out – AIR applications that download files on Leopard only work if there are no spaces in the file name or the spaces have been ‘URL Encoded’ ( like: file%20name%20with%20spaces.jpg ).
Here’s my test case to see what I mean – DownloadTest.air
In my test case on XP, Vista and Tiger, either file will download as expected. On Leopard, “hungoversanta.jpg” will download successfully, while “hung over santa.jpg” will not. The tricky part is, a file with the name does get saved but it contains no data.
If you click the ‘Encode URLs’ button in the test case, it will do just that, encode the spaces in the url. Now both files will successfully download.
Here’s the quick work around I used – do a regex replace to encode the url strings like this:
var regex:RegExp = / /g;
var urlString:String = “my file with spaces.jpg”;
urlString = urlString.replace(regex,’%20′);
// returns “my%20file%20with%20spaces.jpg”
I hope this saves others from the few hours I spent trying to figure out this problem. If anyone knows of a ‘URL Encode’ utilty method, please let me know. I know that you can encode using the URLVariables class but that seems to be more geared at querystrings and not so much on entire URL Strings.
I’d love to hear if others have had this problem and if my theory/solution works for you.
Thanks! :)