Adobe AIR HTML - 如何动态加载位于应用程序存储中的图像?

发布于 2024-09-18 05:22:50 字数 982 浏览 4 评论 0原文

我正在开发一个 AIR 应用程序,它生成动态客户端演示文稿,从 PHP 框架 API 中提取所有必要的数据。在此过程中,我下载了大量图像并将它们本地存储在用户的应用程序存储 (air.File.applicationStorageDirectory) 中。

旁注:我动态填充的 HTML 视图位于 IFRAME 沙箱中。

我有一个解析脚本,它尝试获取 JSON 数据并使用必要的字段填充页面。其中许多字段都是我需要在本地引用的图像。我想我也许可以使用 简单地生成 URL,但它似乎并没有实际加载图像。我的猜测是 AIR 不会动态处理 app-storage: url 引用。有解决方法吗?我可以使用 jQuery 和 load() 吗?

这是我正在使用的当前代码,该代码不起作用:

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;
    }
}

我想我可能走在正确的轨道上,因为返回结果是

air.File.applicationStorageDirectory('test')

app-storage:/test

任何帮助将不胜感激!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花辞树 2024-09-25 05:22:50

最终的解决方案是,我必须正确设置 IFRAME 以获得应用程序安全级别访问权限,授予其正确使用处理 app-storage url 的权限。对于那些有兴趣了解如何执行此操作的人,第一步是将您希望直接加载的 IFRAME 文件直接加载到应用程序的主目录中:

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

此沙箱中的主要区别在于它不< /em> 具有参数 sandboxRoot

值得注意的是,在我的任何测试过程中,我从未遇到过任何安全错误。 AIR 本身似乎没有正确处理应用程序存储 URL。

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.

可可 2024-09-25 05:22:50

人们交谈比您需要在那里允许安全策略。

people talking than you need to allow security policy there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文