1

I know how to upload a file using action script

See upload a zip file using HTTP POST via actionscript 3.0 for details.

Code replicated here:

var urlRequest:URLRequest = new URLRequest(PUBLISH_ZIP_FILE_URL);
// set to method=POST
urlRequest.method = URLRequestMethod.POST;

var params:URLVariables = new URLVariables();

params['data[File][title]'] = 'Title1';
params['data[File][description]'] = 'desc';

// this is where we include those non file params and data
urlRequest.data = params;


// now we upload the file
// this is how we set the form field expected for the file upload
file.upload(urlRequest, "data[File][filename]");

The web app responsible for accepting the file upload will return a JSON string containing details such as file size, id number, etc.

How do I access this JSON result string in my actionscript?

1 Answer 1

1

From the FileReference docs, you need to add a handler to your FileReference instance for the uploadCompleteData event:

import flash.events.*;

// now we upload the file
// this is how we set the form field expected for the file upload
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadCompleteDataHandler);
file.upload(urlRequest, "data[File][filename]");

private function uploadCompleteDataHandler(event:DataEvent):void  
{
     trace("uploadCompleteData data: " + event.data);
}
Sign up to request clarification or add additional context in comments.

5 Comments

i have a handle like this already. let me go try this out. by the way, is there a good way to debug action script that communicates with a web service like the way we use Firebug to look at GET and POST params in the HTTP requests?
So what do you get if you trace event or event.data in your handler? Charles (web debugging proxy application) is pretty useful for debugging webservice calls from Flash: charlesproxy.com
what else can I use other than Charles? Do you use Charles?
Yeah I use Charles. The free demo is pretty usable from memory (I think it closes itself down after a while). If you're using Flash builder you can put a breakpoint in your handler to inspect the contents of the event object. There are plenty of tools for testing webservices in isolation also. If you're using Chrome, the simple REST client extension is handy: chrome.google.com/webstore/detail/…
If you are testing in Firefox only, you can use a plugin called Tamper Data. But FWIW Charles is better / Worth the cost.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.