views:

6414

answers:

3

I'm using HTTPService with a POST operation to submit a Base64 encoded file (taken from bitmap data within the app) but I could really do with getting some idea of the progress of the POST operation (e.g. like the FileReference.upload()).

I don't think this is possible, but it would be awesome if it is (via any means, I'm willing to change my setup to get this).

+4  A: 

Do not use HTTPService. Use URLRequest, URLLoader, and URLVariables.

If your using an HTTPService tag, get ride of it and replace it with a Script tag filled with something like ...


private function forYou() : void{
     var req : URLRequest = new URLRequest("PUT YOUR URL HERE")
     var loader : URLLoader = new URLLoader();
     var params : URLVariables = new URLVariables();
     params.WHATEVER = WHATEVER YOU WANT IT TO BE;
     req.data = params;
     req.method = URLRequestMethod.POST;
     loader.addEventListener(ProgressEvent.PROGRESS, YOUR LISTENER FUNCTION NAME);
     loader.load(req);
}

Assign this function name to the creationComplete attribute of the root tag.

If your not using an HTTPService tag, just get ride of the HTTPService object in your actionscript and use the above code.

ForYourOwnGood
This is a good answer for downloading information, but the question is about uploading.
Ross Henderson
A: 

This worked well for me to consume a REST web service:

http://code.google.com/p/as3httpclient/wiki/Links

Example

Brandon
A: 

This isn't possible with HTTPService. Its only events are result, fault, and invoke (other than the non-relevant inherited events of activate and deactivate).

To get progress information on an upload process, the server would have to provide the information, which would require a means of communication between the server and the client during the operation, which isn't there for a regular HTTP POST operation.

One option might be to create an object on the server that would be instantiated whenever the server began receiving POST data from your client. It would then keep track of the progress and expose that data to the rest of your server-side application. Your client could then initiate a polling system that would request the value of that particular variable.

Seems like kind of a far-fetched option, though...

Ross Henderson