views:

392

answers:

3

I'm currently creating a series of as3 / PHP classes that upload - encode + download images.

Anyone know if there's a way to report progress while posting a ByteArray to the server?

the ProgressEvent is not working - at least not in the case of uploading a ByteArray -
it reports progress only after it's been uploaded

here's a stripped version of the code I'm using ...

urlLoader=new URLLoader;
urlLoader.dataFormat=URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(ProgressEvent.PROGRESS,progressHandler);
//          
function progressHandler(e:ProgressEvent):void {
              trace(e.bytesLoaded/e.bytesTotal);

}

thanks -MW

A: 

Are you using an URLLoader to send it? You should beable to add a ProgressEvent listener to it.

EDIT: You might need to send data back from PHP, see here: http://stackoverflow.com/questions/99319/grab-a-progressevent-from-a-post-upload-in-as3

http://www.ibm.com/developerworks/library/os-php-v525/index.html

Tyler Egeto
hmm, the link shows how to do it in JavaScript, now if I could only find out how to do it in Actionscript.
MW
The AS3 implementation would be essentially the same thing, using a URLLoader to ping a getprogress.php file
Tyler Egeto
unfortunately the hosting I'm using ( Mediatemple Grid server ) can't support PHP-APC .. thanks for your help - guess I'd have to switch hosts to find out -- anyone out there achieved a progress event with this technique?
MW
A: 

URLLoader, while it supports sending data to the server, was designed for downloading data. The ProgressEvents are fired only as data from the server is received. In the case of an upload, this means that all the ProgressEvents will occur after the upload is already finished.

If the file is off the user's hard drive, you might be able to use the FileReference class to upload it to the server instead, which does dispatch ProgressEvents as the upload progresses (and not just the download).

Also, if you are using Flash Player 10, then it is possible to load a file off of the user's computer directly into Flash, manipulate it, then save it back out again (or just use it in Flash) without involving the server. This may not be an option, however, if you are encoding images from/into a format that Flash (or 3rd-party ActionScript libraries) cannot understand.

Cameron
thanks for the reply - part of the set of classes I'm constructing uses FileReference as an option. so the (original) upload, download, encode, and FileReference (what I'm calling snapshot) all have progress events -- I just can't figure out how to add one to the ByteArray upload.
MW
As a workaround, you could ask the server for a certain amount of dummy information of a known size, figure out how long the transfer took and estimate the speed of the user's network that way. Using this estimate, you could give a projected time estimate for the ByteArray upload.
Cameron
A: 

You should look into this ActionScript 3 library: http://code.google.com/p/as3httpclient/

It may solve your problem. I'm currently using it on a project and its been great.

Matt W
thanks Matt , I'll check it out
MW
As a note, if you're using it on a web based app, you'll need to look into a socket policy file server. http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security_04.html
Matt W