可以使用的URLLoader爲二進制的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);
首先得到的BitmapData的圖像:
// 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);
然後得到的ByteArray:
var byteArray : ByteArray = new JPGEncoder(90).encode(bmd);
和使用上面的URLLoader代碼將圖像發送到服務器。
它會正常工作,除非你不會像FileReference.upload那樣獲得文件上傳進度。如果您可以使用URLLoader使上傳進度工作,請在此發佈您的答案。