<fx:AnandVardhan/>

lights..camera..Action..Script.. ing..

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

11 Responses to “Receiving data in response to file upload in Flex using FileReference”

  1. Tony Fendall
    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.

  2. kailas R. Deokar
    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.

  3. Chee Beng
    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.

  4. Anand
    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.

  5. Umer Khan
    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?

  6. Razvan Pat
    August 10th, 2008 @ 1:45 pm

    Thank you, you just saved me from a lot of headaches. :)

  7. Amit Kumar
    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 !!

  8. Mohammed
    November 9th, 2009 @ 9:19 pm

    Thanks alot! you have saved my life

  9. JB
    November 25th, 2009 @ 11:31 pm

    Perfect! Thanks for sharing.

  10. JP
    December 4th, 2009 @ 12:52 pm

    Thanks Mate!

    This had me stumped for so many hours. And I was so close to it a few hours ago too. Except I was trying to use “DataEvent.DATA” instead of “DataEvent.UPLOAD_COMPLETE_DATA”.

    Thanks for sharing and putting me back on track.

  11. Ronen Tsamir
    January 27th, 2010 @ 9:38 pm

    Great, TNX

Leave a Reply