怎样的BitmapData上传到服务器(ActionScript 3的)?服务器、BitmapData、ActionScript

2023-09-08 13:37:06 作者:老尼法号靓女

我有位图数据。我希望把它上传到使用的URLLoader服务器。我尝试过很多办法,但没有结果。 这是我目前的code在ActionScript 3:

I have bitmapData. I want to upload it to a server using URLLoader. I tried many ways, but with no result. This is my current code in ActionScript 3:

import flash.net.URLLoader;
import flash.net.URLRequest;
import mx.graphics.codec.JPEGEncoder;
...
var jpg:JPEGEncoder = new JPEGEncoder();
var myBytes:ByteArray = jpg.encode(bitmapData);
var uploader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("uploadFile.php");
request.contentType = "application/octet-stream";
request.data = myBytes;
uploader.load(request);

我把一个对象的位图数据和连接code到JPG。从那以后,我尽量JPG字节发送到服务器上的文件uploadFile.php。但也有没有错误,也没有积极的结果。 我会很感激的任何建议/意见。

I take an object bitmapData and encode it to jpg. After that I try to send jpg-bytes to the file "uploadFile.php" on the server. But there are neither errors nor positive result. I will be grateful for any suggestions/advices.

推荐答案

这是AS3 code我以前用过这个 - 这使得在请求主体的二进制数据的POST请求:

This is the AS3 code I've used for this before - this makes a POST request with binary data in the request body:

var url_request:URLRequest = new URLRequest();
url_request.url = "http://server.com/upload.php";
url_request.contentType = "binary/octet-stream";
url_request.method = URLRequestMethod.POST;
url_request.data = myByteArray;
url_request.requestHeaders.push(
 new URLRequestHeader('Cache-Control', 'no-cache'));

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
// attach complete/error listeners
loader.load(url_request);

我注意到,你不设置.dataFormat Binary或。方法为POST。

I notice that you're not setting .dataFormat to BINARY or .method to POST.

请注意,这可能是你正在运行到一个安全问题。我见过的情况下,code这样必须在响应用户操作(如单击按钮)执行。

Note that it could be a security issue you're running into. I've seen cases where code like this must execute in response to a user action (like a button click).

您也应该检查你的服务器日志,看看该请求是否正在给服务器。请注意,如果没有一个完全合格的URL(以http://),它假定服务器在同一位置的SWF文件提供的PHP文件

You should also check your server logs to see whether the request is making it to the server. Note that without a fully-qualified url (starts with http://), it assumes the server serves your PHP file from the same location as your SWF file.