gpt4 book ai didi

actionscript-3 - 使用 URLLoader 时出现意外的 Flash 安全异常

转载 作者:行者123 更新时间:2023-12-04 06:49:35 24 4
gpt4 key购买 nike

我想要完成的是使用 URLLoader 类和 URLRequest 将一些二进制数据(特别是表示 PNG 图像的 ByteArray)上传到服务器。

当我设置 contentType将 URLRequest 的属性改为“multipart/form-data”而不是默认值,即对 urlLoader.load() 的调用导致安全异常。

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

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

请注意,我的 SWF 是从开发服务器而不是本地文件系统(准确地说是 Google App Engine 开发服务器)提供的。

这是代码:

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

最佳答案

可能是 contentType不是指您发送什么数据,而是指您收到什么数据。尝试设置 requestHeaders ,这应该工作:

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

另外,我在我的一个项目中找到了一段代码。该代码工作并使用 POST 将一些二进制 JPEG 数据发送到服务器。前段时间我做了它,我无法解释为什么我这样做,但也许它有帮助。我按原样粘贴它:
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);
}

关于actionscript-3 - 使用 URLLoader 时出现意外的 Flash 安全异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1270347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com