0

I am trying to save images to the disk in an AIR app for smartphones. I need a method, that can convert safely Web URLs to valid filenames on Android & iOS (if it would retain Windows/Mac compatibility it'd be good.), and i can get back the original full URL from the filename. For example:
Input is:
http://www.google.hu/search?client
Encoded format is something like (this is just some example i found out now):
http%d%s%swww.google.com%tsearch%rclient%z

And i'd need a method to convert it back. I've looked into BASE64 - but this allows the "/" character, and im afraid to use HEX encoding, because this will generate super long filenames, and URLs can be lengthy.
According to another question, in iOS the max length pathname is 1024 bytes: max length of file name

Anyone has a solution for AIR? Basically this is the same question as Convert between URL and windows filename (Java)? - just for AIR, iOS, Android.

Or should i simply modify a BASE64 encoder, and do some hacks for long filenames?

Community
  • 1
  • 1
sydd
  • 1,824
  • 2
  • 30
  • 54

1 Answers1

1

Why not use escape() and unescape(), which essentially replaces all evil characters with safe ones. Similar to JavaScript's escape() function.

(EDIT) I stand corrected, in addition to the escape you would still need to replace the slash and star (/*) characters, and any other invalid characters, as you have pointed out.

Out of curiosity, why not just write a separate text file with the url in it, and name it the same as your image? Or even use a database? This should ensure you never get a crazy long url greater than the max file name limit, and you wouldn't have to worry about escaping/converting characters either.

ToddBFisher
  • 11,370
  • 8
  • 38
  • 54
  • Because it does not replace evil characters, like '*' or '/' – sydd Nov 27 '11 at 14:24
  • If i'd write the URL in a text file, i'd have the problem of unique image names (how can i differentiate only from the image name between sitea.com/logo.jpg and siteb.com/logo.jpg?). I am not using a database, because i try to make a local cache for Flex's image types: BitmapImage and Image. The problem is that these need a LoaderInfo to get the loaded image - and a DB query cant produce this. – sydd Nov 27 '11 at 21:16