I am using simple as3+php, no FMS or such in between. I am making a video recording app, and I can capture frames and convert them to flv encoded bytearray. But the problem happens when I try to save it on the server. If I convert the bytearray to a string via base64 encode and then send that string to the server, all works ok, but the problem is that since it’s an video file, it can be pretty big, like 20mb or so, and hence it takes a long time to encode it and then upload it, moreover normally a script timeout will occur during the encoding. To make things faster, I am trying to send the bytearray directly, but my firebug net panel shows me that the data being sent is around 20-46 bytes. Please tell me what I am doing wrong.
//var encoded_str = Base64.encodeByteArray(_baFlvEncoder.byteArray);
//Handle Upload
/*var url_data:URLVariables = new URLVariables();
url_data.data = _baFlvEncoder.byteArray;*/
var url_ref:URLRequest = new URLRequest("save_vid.php");
url_ref.contentType = 'application/octet-stream';
url_ref.data = _baFlvEncoder.byteArray;//url_data;
url_ref.method = URLRequestMethod.POST;
var urlLoader:URLLoader = new URLLoader();
// just making sure the server knows we are sending data in proper format
//urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
try {
urlLoader.load( url_ref );
} catch (e:Error) {
trace(e);
}
And my PHP code:
<?php
echo 'Data:<pre>';
print_r($_POST);
echo '</pre>';
//$decodedData= base64_decode($GLOBALS[ 'HTTP_RAW_POST_DATA' ]);
//file_put_contents("test.flv",$decodedData);
file_put_contents("test.flv",$GLOBALS[ 'HTTP_RAW_POST_DATA' ]);
?>
In the
URLRequest.datadocumentation, it specifies the option of using a ByteArray directly.Here,
You can then skip the
URLVariablesobject, which relies on encoding your transmitted data asapplication/x-www-form-urlencoded, which is not well suited to binary data (even if it were handled properly, which it may not be).