Flash/Flex 跨域问题 - 对来自 AWS S3 的图像使用 BitmapData.draw() 导致 SecurityError:错误 #2122:安全沙箱违规 [英] Flash/Flex crossdomain issue - using BitmapData.draw() for image from AWS S3 results in SecurityError: Error #2122: Security sandbox violation
问题描述
我在包含来自我的 AWS S3 存储桶的图像的 DisplayObject 上使用 BitmapData.draw().当我将 S3 图像 URL 设置为 Image 对象的源时,图像在 swf 中加载良好,但是当我在其上使用 BitmapData.draw() 时,它给了我这个错误:
I am using BitmapData.draw() on a DisplayObject that includes an image from my AWS S3 bucket. The image loads fine in the swf when I set the S3 image URL as the source for an Image object but when I use BitmapData.draw() on it, it gives me this error:
SecurityError:错误 #2122:安全沙箱违规:BitmapData.draw:https://www.example.com/Example.swf 无法访问https://s3.amazonaws.com/example-images/example.jpg.策略文件是需要,但在此媒体上未设置 checkPolicyFile 标志已加载.
SecurityError: Error #2122: Security sandbox violation: BitmapData.draw: https://www.example.com/Example.swf cannot access https://s3.amazonaws.com/example-images/example.jpg. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
AS 代码:
var bmpd:BitmapData = new BitmapData(objectToDraw.width,objectToDraw.height);
bmpd.draw(objectToDraw);
我尝试将以下 crossdomain.xml 文件放在我的 S3 存储桶根目录中,但无济于事:
I have tried putting the following crossdomain.xml file in my S3 bucket root to no avail:
<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>
推荐答案
在 S3 上访问文件有两种方式:
There are two ways to access files on S3:
s3.amazonaws.com/[bucket name]/file.ext
[存储桶名称].s3.amazonaws.com/file.ext
由于crossdomain.xml文件需要在域的根文件夹下,而您无权访问s3.amazonaws.com
的根文件夹,因此您无法控制crossdomain.xml
文件(如果您使用第一种方法)
Since the crossdomain.xml file needs to be in the root folder of the domain, and you don't have access to the root folder of s3.amazonaws.com
, you can't control the crossdomain.xml
file if you are using the first method
如果您使用第二种方法,您可以在存储桶的根文件夹中放置一个 crossdomain.xml
文件,Flash Player 将正确使用该文件.
If you are using the second method, you can put a crossdomain.xml
file in the root folder of your bucket and it will be used correctly by the Flash Player.
这篇关于Flash/Flex 跨域问题 - 对来自 AWS S3 的图像使用 BitmapData.draw() 导致 SecurityError:错误 #2122:安全沙箱违规的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!