2011-07-28 6 views
0

データのバイト配列(そのイメージソース)を他のバールと一緒にサービスに送る必要があります。 私は、次のURLRequestではなくHTTPServiceを使用してデータを送信する必要があります。コンテンツタイプがデータを乱していますか?

var request:URLRequest = new URLRequest ('http://www.mydomain.com/upload.php'); 
      var loader: URLLoader = new URLLoader(); 
      request.contentType = 'application/octet-stream'; 
      request.method = URLRequestMethod.POST; 
      request.data = byteArrayOfImage; 
      loader.load(request); 

とPHPで

$fp = fopen('myImage.jpg', 'wb'); 
fwrite($fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ]); 
fclose($fp); 

のようなものを使用してバイト配列を送信する場合、これは画像の罰金が保存されます。しかし、私は次のものを使用しようとしているので、私は余分なvarsを送信する必要があります。

var service : HTTPService = new HTTPService(); 
service.method = "POST"; 
service.contentType = 'application/x-www-form-urlencoded'; 
service.url = 'http://www.mydomain.com/upload.php';   
var variables : URLVariables = new URLVariables();  
variables.imageArray = myImageByteArray; 
variables.variable2 = "some text string"; 
variables.variable3 = "some more text";    
service.send(variables); 
PHP

$byteArray= $_REQUEST["imageArray"]; 
$fp = fopen('myImage.jpg', 'wb'); 
fwrite($fp, $byteArray); 
fclose($fp); 

で次に

しかし、これは動作しません。保存されたファイルのファイルサイズが異なり、後でイメージとして保存されません。 私は何が欠けています。作業中のコンテンツタイプがapplication/octet-streamであり、動作しないコンテンツタイプがapplication/x-www-form-urlencodedですか?

答えて

0

私は回避策を提供する同様の質問を見つけました。理想的ではありませんが、機能します。

http://www.google.es/search?sourceid=chrome&ie=UTF-8&q=as3+base64+encoder

http://code.google.com/p/jpauclair-blog/source/browse/trunk/Experiment/Base64/src/Base64.as

それでは、私がやったことはBase64のコードを使用して以下のとおりです。

var encodedString : String = Base64.encode(imageByteArray); 
var service : HTTPService = new HTTPService(); 
service.method = "POST"; 
service.contentType = 'application/x-www-form-urlencoded'; 
service.url = 'http://www.mydomain.com/upload.php';   
var variables : URLVariables = new URLVariables();  
variables.imageArray = encodedString; 
variables.variable2 = "some text string"; 
variables.variable3 = "some more text";    
service.send(variables); 

は、PHP側

$byteArray= $_REQUEST["imageArray"]; 
$byteArray= base64_decode($byteArray); 
$fp = fopen('myImage.jpg', 'wb'); 
fwrite($fp, $byteArray); 
fclose($fp); 

にこれが有効なのjpg画像を保存します。理想的ではありませんが動作しますが、私はまだバイト配列のエンコーディングを含まないソリューションが好きです。この回避策が見つかったとしても、お気軽にお答えください。

関連する問題