Receiving data in response to file upload in Flex using FileReference
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 ![]()
July 15th, 2007 at 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 at 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 at 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 at 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 at 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 at 1:45 pm
Thank you, you just saved me from a lot of headaches.