views:

16

answers:

2

I have a flash app that needs to download a file, whose name contains UTF-8 characters.

Internally, the filename is read from a UTF-8 XML file, e.g. "my filé.pdf". The code goes something like this:

url = get_filename_from_XML();
req = new URLRequest( url );

ref = new FileReference();
ref.download( req );

The problem is that the URL is encoded in Latin1, i.e. the é is encoded as %E9 instead of %C3%A9 (according to FireBug). How can I get Flash to encode the URL correctly?

A: 

You could try escape() or encodeURI() Check the docs: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/

url = get_filename_from_XML();

url = escape(url);
//url = encodeURI( url );

req = new URLRequest( url );
PatrickS
The escape method gives me the same thing - %E9. encodeURI correctly encodes it, but when I pass that to the URLRequest's constructor, it creates an error 2087 on the ref.download() method.
Kelsey Rider
A: 

I found a hack:

url = decode( encodeURI( url ) );

req = new URLRequest( url );

The encodeURI turns it into Latin1, URL-encoded, then decode turns it into Latin1 text (effectively changing the internal encoding of the String). The URLRequest then encodes the bytes correctly, using %C3%A9 for é.

Kelsey Rider