views:

9

answers:

2

I'm working on an AIR application which generates a dynamic client presentation, pulling all necessary data from a PHP framework API. In the process, I download a large number of images and store them locally in the user's app-storage (air.File.applicationStorageDirectory).

Side note: the HTML view I am dynamically populating is located in an IFRAME sandbox.

I have a parsing script which attempts to take JSON data and populate the page with the necessary fields. Many of these fields are images that I need to locally reference. I thought I might be able to simply generate the URL using <img src="app-storage:/path/to/img.jpg"> but it doesn't seem to actually load the image. My guess is AIR doesn't handle app-storage: url references dynamically. Is there a work-around for this? Could I perhaps use jQuery and load()?

Here is the current code I am using which is not working:

var pos = filename.lastIndexOf(".");
if (pos != -1) {
    ext = filename.substr(pos + 1, filename.length);
    switch (ext) {
        case 'gif':
        case 'jpg':
        case 'jpeg':
        case 'png':
        default:
            // update the source value
            $field.attr('src', 'app-storage:' + filename);
            break;
    }
}

I thought I might be on the right track because the return result of

air.File.applicationStorageDirectory('test')

was app-storage:/test

Any help would be greatly appreciated!

A: 

people talking than you need to allow security policy there.

Eugene
A: 

The solution ended up being that I had to properly set the IFRAME to have Application security level access, granting it privileges to use handle app-storage urls properly. For those interested in knowing how you can go about doing this, the first step is to simply have the IFRAME file you wish to load directly in the application's main directory:

<iframe id="childFrame" src="child.html" documentRoot="app:/" allowcrossDomainxhr="true" width="100%" height="100%"></iframe>

The key difference in this sandbox is that it doesn't have the parameter sandboxRoot.

It's worth noting that I never once experienced any security errors during any of my testing. It seemed as though the app-storage URL was just not properly being handled by AIR itself.

cballou

related questions