Mike Chambers

code = joy

Getting the File URI of a File in an AIR app’s install directory

with 2 comments

I am currently working on some code that runs in Adobe AIR where I need to access the File URL (file:/) of a file located in the AIR app’s install directory.

Normally, you could get the URI, by accessing the url property of the File object which will return a well formed, absolute file:/ URL. However, this doesn’t work for files located in the AIR app’s install directory.

var f:File = new File("app:/icon.png");
trace(f.url); //app:/icon.png

 

While the app:/ URI will work within your AIR application, it will not work if you need to pass that URI to a non AIR application.

Here is the workaround for how to get the File URL of a file in the application install directory:

var fPath:String = new File(new File("app:/icon.png").nativePath).url;
trace(fPath);

 

This will give you an absolute file URI similar to:

file:///Users/mesh/Documents/Flex%20Builder%203/AppName/bin-debug/icon.png

 

Of course, this is a bit of a hack, and not that efficient (requires two File instances), but it works.

Written by mikechambers

November 6th, 2008 at 1:57 pm

Posted in General

2 Responses to 'Getting the File URI of a File in an AIR app’s install directory'

Subscribe to comments with RSS or TrackBack to 'Getting the File URI of a File in an AIR app’s install directory'.

  1. Did you already file a suggestion to the sdk team?

    funkyboy

    6 Nov 08 at 4:57 pm

  2. [...] read more @ Getting the File URI of a File [...]

Leave a Reply