Receiving data in response to file upload in Flex using FileReference
Posted on | July 13, 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 ![]()
Comments
7 Responses to “Receiving data in response to file upload in Flex using FileReference”
Leave a Reply




July 15th, 2007 @ 11:17 pm
It’s a pitty that this requires the user to have the latest version of the flash player, but it is really convenient.
July 21st, 2007 @ 11:17 am
hi Anand,
This is kailas Deokar, i want a brif example to upload the local file on to server.Plz help me to achieve this.
October 9th, 2007 @ 2:21 am
Very nice of you to share this with us.
May I ask whether do you have a solution for FileReference to return the path? Here is my problem in more details.
I want to upload a file to server. FileReference.browse() is doing a fine job allowing user to select a file. However, I would like to gain access to the path for some reasons. It is a pitty FileReference seems like it is not able to do that!
Thanks.
April 26th, 2008 @ 5:36 pm
You can never get local path from client due to security reasons. but if you are working in AIR it provides you documentLocalPath passed with file object.
July 16th, 2008 @ 8:34 am
hey?
can you give me a complete code or ne sample how to use this filereference. i got many example but they all need servelt? do i need a servlet too? let me know how to do it?
August 10th, 2008 @ 1:45 pm
Thank you, you just saved me from a lot of headaches.
December 11th, 2008 @ 12:34 pm
Super !!!
You made my day… I stumbled across this problem and was looking through API with no such documentation. I was about to give and then thought of Googling and found your code snippet…
Thanks for your help !!