Apollo File Path Gotcha
Posted by brandonthedeveloper at June 3rd, 2007
Here’s an Apollo gotcha I’ve been meaning to post for a few weeks now.
In a super secret app I am working on in Apollo, I need to allow the user to open files that have been saved to the App-Storage directory of the application. Sounds easy enough and it is easy enough but coming from a .net background I messed it all up.
You would think this would work but it doesn’t:
var file:File = File.appStorageDirectory.resolve(imageLib.selectedItem.name);
// pretend there is an image component on stage
myImage.source = file.nativePath;
// file.nativePath returns something like this on Windows:
C:\Documents and Settings\brandon\Application Data\MyApolloApp\Local Store\hungOverSanta.jpg
and this on Mac:
/Users/brandon/Library/Preferences/MyApolloApp/Local Store/hungOverSanta.jpg
both file paths are correct and if you plug them into an explorer window will pull up the image.
The correct way is like this:
var file:File = File.appStorageDirectory.resolve(imageLib.selectedItem.name);
// pretend there is an image component on stage
myImage.source = “app-storage:/” + file.name;
Huh?
I know there is some internal string association going on there but really, that is different than any type of File System Object I’ve ever seen. I only found one reply about it at the Adobe Forums. Hopefully my post here will save someone else the headache and (if I wasn’t bald already) hair pulling I went through while trying to figure this out.



It is not clear to me from your code samples what you are trying to do.
What is myImage?
Is it a Flex image control? If so, that only take URIs (http, file://, app-resource:/, etc…), and not native paths.
mike chambers
mesh@adobe.com
mike chambers
Hey Mike,
Sorry I wasn’t more clear but I had this little comment in my code:
// pretend there is an image component on stage
then…
myImage.source = “app-storage:/” file.name;
The fact that I couldn’t use a native path was the whole ‘gotcha’. ;)
Say the user has saved media files to their appStorageDirectory like .mp3, .flv, .png…
Most other programming languages would allow you to type in the fully qualified path like the one output by File.nativePath to open a file.
My problem was that because I’m used to that type of programming behavior, I never even thought of putting in a string reference as a file path like ‘app-storage:/’ as most other programming langs would read it as ‘“app-storage:/hungoversanta.jpg”.
All in all, it’s figured out and sometimes just one little code snippet can save another developer from eating up time on the same problem.
brandonthedeveloper