Archive for the ‘Tutorials’ Category

Receiving data in response to file upload in Flex using FileReference

Friday, July 13th, 2007

I don’t know how much you have faced this problem and were unable to figure out the way to do it. Today I had this problem and I found the solution and wanna share this with all of you. So here it is,

My problem was after uploading data to a server via Flex i.e. FileReference.upload,  there was no way to receive data back from the server in response to your upload. A common requirement. e.g. Upload a file for processing, server returns results (typically status).

Solution: Add a listener on your FileReference object: (Make sure you have flash player build version greater than 9.0.28). To check this right click on the Flash application opened in Bowser and choose about.

fileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, responseHandler);

private function responseHandler( event:DataEvent ) :void
{
var response:XML = XML( event.data );
Alert.show(response.toString())
}

Have fun :)