意外的闪存安全异常使用的URLLoader当 [英] Unexpected Flash Security Exception When Using URLLoader

查看:200
本文介绍了意外的闪存安全异常使用的URLLoader当的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做到的是使用结合URLLoader类用的URLRequest上传一些二进制数据,具体的ByteArray重新presenting PNG图像,到服务器。

当我设置URLRequest的的contentType 属性的multipart / form-data的,而不是默认情况下,调用 urlLoader.load ()导致安全异常。

当我离开的contentType 属性设置为默认,它工作正常,但需要很长的时间(成比例的PNG文件的长度)将文件上传到服务器

所以,我的问题是,为什么我会收到此安全异常?我怎么能避免呢?

请注意,我的SWF正在提供从开发服务器,而不是本地文件系统(谷歌应用程序引擎开发服务器是precise)。

下面是code:

  VAR pngFile:的ByteArray = PNGEn coder.en code(位图数据);

VAR的URLRequest:的URLRequest =新的URLRequest('/ API / uploadImage');

//这一行的code,调用URLLoader.load()方法抛出以下安全异常:
//'引发SecurityError:错误#2176:某些动作,比如那些显示一个弹出式窗口,只可以通过鼠标点击或按键preSS在用户交互来调用,例如
urlRequest.contentType =的multipart / form-data的;

urlRequest.method = URLRequestMethod.POST;
请将URLRequest.data = pngFile;
urlRequest.requestHeaders.push(新URLRequestHeader(缓存控制','无缓存'));

的URLLoader =新的URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.addEventListener(引发Event.COMPLETE,onUploadComplete);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR,onUploadError);

NextFrame.addCallback(函数(){
对URLLoader.load(的URLRequest);
});
 

解决方案

这可能是可能的,的contentType 指的不是你送什么数据,而是要什么样的数据,你接收。尝试设置 requestHeaders ,这应该工作:

  urlRequest.requestHeaders.push(新URLRequestHeader(内容型,多部分/表单数据));
 

另外,我发现了一张code凡在我的项目之一。在code ++工程,并将一些二进制的JPEG数据到服务器,使用POST。我DIT它前一段时间,我无法解释为什么我做的事这种方式,但也许它帮助。我粘贴它是:

 功能送出数据(submitPath:字符串,descriere:字符串):无效{
    //构建HTTP请求上传JPEG到服务器
    VAR标题:的URLRequestHeader =新URLRequestHeader(内容型,应用程序/八位字节流);
    VAR jpgURLRequest:的URLRequest =新URLRequest(submitPath+'/id/'+player.id+'/path/'+player.contentPath.replace('/','')+'/width/'+player.videoWidth+'/height/'+player.videoHeight+'/descriere/'+descriere+'/timp/'+time);
    jpgURLRequest.requestHeaders.push(头);
    jpgURLRequest.method = URLRequestMethod.POST;
    jpgURLRequest.data =截图;

    //将数据发送给服务器
    VAR发件人:的URLLoader =新的URLLoader();
    sender.load(jpgURLRequest);
}
 

What I am trying to accomplish is to upload some binary data, specifically a ByteArray representing a PNG image, to a server using the URLLoader class in conjunction with URLRequest.

When I set the contentType property of the URLRequest to 'multipart/form-data' instead of the default, the call to urlLoader.load() results in a security exception.

When I leave the contentType property as the default, it works fine, but takes a long time (proportional to the length of the PNG file) to upload the file to the server.

So, my question is WHY am I getting this security exception? And how can I avoid it?

Note that my SWF is being served up from a development server, not the local filesystem (the Google App Engine development server to be precise).

Here is the code:

var pngFile:ByteArray = PNGEncoder.encode(bitmapData);

var urlRequest:URLRequest = new URLRequest('/API/uploadImage');

// With this line of code, the call to urlLoader.load() throws the following security exception:
// 'SecurityError: Error #2176: Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.'
urlRequest.contentType = 'multipart/form-data';

urlRequest.method = URLRequestMethod.POST;
urlRequest.data = pngFile;
urlRequest.requestHeaders.push(new URLRequestHeader('Cache-Control', 'no-cache'));

urlLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.addEventListener(Event.COMPLETE, onUploadComplete);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onUploadError);

NextFrame.addCallback(function () {
	urlLoader.load(urlRequest);
});

解决方案

It could be possible that contentType does not refer to what data you send, but to what data you receive. Try to set the requestHeaders, that should work:

urlRequest.requestHeaders.push(new URLRequestHeader('Content-type', 'multipart/form-data'));

Also, I've found a piece of code where in one of my projects. The code works and sends some binary JPEG data to the server, using POST. I dit it some time ago and I can't explain why I did the things this way, but maybe it helps. I'm pasting it as is:

function sendData(submitPath:String, descriere:String):void {
    // building the url request for uploading the jpeg to the server
    var header:URLRequestHeader = new URLRequestHeader('Content-type', 'application/octet-stream');
    var jpgURLRequest:URLRequest = new URLRequest(submitPath+'/id/'+player.id+'/path/'+player.contentPath.replace('/','')+'/width/'+player.videoWidth+'/height/'+player.videoHeight+'/descriere/'+descriere+'/timp/'+time);
    jpgURLRequest.requestHeaders.push(header);
    jpgURLRequest.method = URLRequestMethod.POST;
    jpgURLRequest.data = screenShot;

    // sending the data to the server
    var sender:URLLoader = new URLLoader();
    sender.load(jpgURLRequest);
}

这篇关于意外的闪存安全异常使用的URLLoader当的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆