2009-09-23 26 views
1

我試圖做一個圖片上傳,用戶可以:
- 瀏覽本地文件與button.browse
- 選擇一個,並將其保存爲一個FileReference。
- 然後我們做FileReference.load()然後綁定數據到我們的圖像控件。
- 在我們旋轉並改變圖像的數據後。
- 並完成我們上傳到服務器。的FileReference和HttpService的瀏覽圖片修改然後上傳它

要改變形象,我得到了顯示圖像的矩陣中的數據並將其轉換然後我再使用新的矩陣,並將其綁定到我的舊形象:

private function TurnImage():void 
{ 
    //Turn it 
    var m:Matrix = _img.transform.matrix; 
    rotateImage(m); 
    _img.transform.matrix = m; 
} 

現在的母校是我真的不知道如何將數據作爲文件發送到我的服務器,導致它沒有存儲在FileReference中,並且FileReference中的數據只讀,所以我們無法更改它或創建新的,所以我不能使用.upload( );.

然後我試着HttpService.send,但我無法弄清楚你如何發送文件而不是mxml。

回答

5

可以使用的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使上傳進度工作,請在此發佈您的答案。