How do I send a bytearray to server and detect progress?

1.2k Views Asked by At

I am using Flash runtime (flash player 10). I have a flv encoded bytearray which I need to send to the server( simple php, no FMS or socket servers) and save there. I can use the urlLoader and post everything but then i won't get the progress percentage, so instead I tried saving it with a file reference like this:

var url_ref:URLRequest = new URLRequest("save_vid.php");    
url_ref.contentType = "multipart/form-data; boundary="+getBoundary();
url_ref.data = _baFlvEncoder.byteArray;
url_ref.method = URLRequestMethod.POST;

var upfileRef:FileReference = new FileReference();
upfileRef.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
upfileRef.addEventListener(Event.COMPLETE, videoUploadComplete);
upfileRef.upload(url_ref);

But when I try this, I am getting an error:

Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.

Any idea how I can do this?

1

There are 1 best solutions below

2
On

Try this:

var vars :URLVariables = new URLVariables();
vars.bytearray  = _baFlvEncoder.byteArray;

var req :URLRequest = new URLRequest("save_vid.php");
req.method = URLRequestMethod.POST;
req.data = vars;

var ldr :URLLoader = new URLLoader();
ldr.addEventListener( Event.COMPLETE, onLoaded );
ldr.addEventListener( IOErrorEvent.IO_ERROR, onIOError );
ldr.addEventListener( ProgressEvent.PROGRESS, onProgress );
ldr.load( req );

function onProgress( e:ProgressEvent ):void 
{           
    trace( "Progress: " + e.bytesLoaded / e.bytesTotal );
}

and in PHP

$bytearray = $_POST['bytearray']