开发者

How to send additional information while posting video data in actionscript?

I'm now saving the snapshot this way:

            vidBmpHolder.draw(main.media.videoLocal);
            var jpgEncoder:JPGEncoder = new JPGEncoder(85);
            var jpgStream:ByteArray = jpgEncoder.e开发者_如何学JAVAncode(vidBmpHolder);
            var loader:URLLoader = new URLLoader();
            var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
            var request:URLRequest = new URLRequest("http://domain.name/savesnapshot.php");
            request.requestHeaders.push(header);
            request.method = URLRequestMethod.POST;
            request.data = jpgStream;
            loader.load(request);

But I want to save additional information :

key=value

Is there a work around?


The proper way is to use URLVariables.

var variables : URLVariables = new URLVariables();
variables.foo= "foo";
variables.bar = "bar";
variables.jpgStream = Base64.encodeByteArray(jpgStream);
request.data = variables;

Note the Base64 encoding, and choose an appropriate library to do this. This should eliminate the need for the header you set.

Then everything should appear as

$foo = $_POST["foo"];
$bar = $_POST["bar"];
$jpgStream = base64_decode($_POST["jpgStream"]);

You may need to do this as multipart, though. Search around for the AS3 UploadPostHelper class, which contains an example.


You can try to add the key value pair at the url, for instance:

new URLRequest("http://domain.name/savesnapshot.php?filename=image1.jpg");

and then, on the php side:

$file_name = $_GET['filename'];

EDIT: Added server side php script.

<?php

$file_name = "image.jpg";

//here you access your file name passed in the url.
if( isset( $_GET["filename"] ) ) $file_name = $_GET["filename"];

$file = fopen($file_name, "w+") or die("Can't open file");

//here you access the bytearray data send form flash
$image_bytes = $GLOBALS["HTTP_RAW_POST_DATA"];

//create the image file
$fwrite = fwrite( $file, $image_bytes );

if ($fwrite === false) echo "Error writing to file: ".$file_name;

fclose($file);

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜