2012-10-29 46 views
2

我試圖從Flash AS3將圖像保存爲我的服務器作爲jpg文件。我發現了一些PHP代碼來做到這一點,但我想在Ruby中做到這一點。我不太清楚如何將下面的代碼轉換爲Ruby。這主要是$GLOBALS["HTTP_RAW_POST_DATA"]部分我不知道如何轉換。如何從Flash AS3文件讀取jpg bytearray

<?php 

    if (isset ($GLOBALS["HTTP_RAW_POST_DATA"])) { 

     // get bytearray $im = $GLOBALS["HTTP_RAW_POST_DATA"]; 

     // save image $f = fopen($_GET['name'], 'wb'); fwrite($f, $jpg); fclose($f); 

    } else echo 'An error occured.'; 

?> 

來源:

http://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed-saving-images-from-flash/

我試着做以下,但所得到的圖像文件劑量不會打開

temp_file = Tempfile.new(['temp', '.jpg'], :encoding => 'ascii-8bit') 
temp_file.write(request.raw_post) 
temp_file.close 

編輯

的圖像數據在request.raw_post

EDIT2

關於圖像,這裏被髮送是怎樣的報頭在AS3創建

var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream"); 
var saveJPG:URLRequest = new URLRequest("http://127.0.0.1:3000/save_image.xml"); 
saveJPG.requestHeaders.push(header); 

saveJPG.method = URLRequestMethod.POST;

回答

1
$GLOBALS["HTTP_RAW_POST_DATA"] 

可以從

request.env["HTTP_RAW_POST_DATA"] 

被抓住並保存它像https://stackoverflow.com/a/2571575/643500

編輯:

是不是在request.body的圖像數據嗎?

我需要看看圖像是如何發送的。你有一個標題Content-Type

+0

那麼,它應該這樣工作嗎? File.open(tempfile.path,'w')do | f | f.write request.env [「HTTP_RAW_POST_DATA」] 結束 – simo

+0

您可以測試它並回答問題。只是調試你有什麼可用的。 –

+0

鏈接中的示例從請求中抓取圖像數據。 –