Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex FileReference prohibited characters

The use of FileReference has a constraint on valid characters.
Error: Error #2087: The FileReference.download() file name contains prohibited characters.
This is fine since I guess the restriction comes from the underlying file system anyway

Is there such a things as a generic way to trim / replace all prohibited characters?

For clarity I am after something like:
var dirty:String = "Eat this !@##$%%^&&*()\/";.txt
var clean:String = dirty.replaceAllProhibitedCharacters();

I am not looking for OS specific regular expressions, but a cross platform solution.

like image 271
MonoThreaded Avatar asked Feb 04 '26 04:02

MonoThreaded


1 Answers

The list of disallowed characters does not change depending on the underlying OS, it is a fixed list. From the documentation for FileReference.download() the list of disallowed characters is:

/\:*?"<>|%

Edit: It looks like @ isn't allowed either.

If you want to remove those characters from an arbitrary string you can do something like this:

var validFileName:String = invalidFileName.replace(/[\/\\:*?"<>|%@]/g, "");

If you want to replace them with something else, then change the second parameter to replace().

Edit: added the @ character; escaped the / character.

like image 172
mamapitufo Avatar answered Feb 05 '26 21:02

mamapitufo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!