您可以使用 URLLoader 将 Binary ByteArray 发送到服务器,例如:
var urlRequest : URLRequest = new URLRequest();
urlRequest.url = 'path to your server';
urlRequest.contentType = 'multipart/form-data; boundary=' + UploadPostHelper.getBoundary();
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = UploadPostHelper.getPostData( 'image.jpg', byteArray );
urlRequest.requestHeaders.push( new URLRequestHeader( 'Cache-Control', 'no-cache' ) );
// create the image loader & send the image to the server:<br />
var urlLoader : URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load( urlRequest );
首先获取图像的位图数据:
// set up a new bitmapdata object that matches the dimensions of the captureContainer;
var bmd : BitmapData = new BitmapData( captureContainer.width, captureContainer.height, true, 0xFFFFFFFF );
// draw the bitmapData from the captureContainer to the bitmapData object:<br />
bmd.draw( captureContainer, new Matrix(), null, null, null, true );
然后得到字节数组:
var byteArray : ByteArray = new JPGEncoder( 90 ).encode( bmd );
并使用上面的 URLLoader 代码将图像发送到服务器。
它会正常工作,除非您不会像从 FileReference.upload 获得的那样获得文件上传进度。如果您可以使用 URLLoader 进行上传进度,请在此处发布您的答案。