Showing posts with label upload. Show all posts
Showing posts with label upload. Show all posts

Thursday, August 2, 2007

Flex and Flash file uploading with return data

source: here

The addition of the FileReference class in AS2 made file uploading significantly easier in Actionscript. However, one issue that remained problematic was the ability to get detailed information back from the server once the upload was complete. The best you could do was to get a '200' response saying the file upload had completed, but there was no easy way to return additional data from the server with respect to the uploaded process .... until now.

Adobe has finally added the missing piece to accomplish a nice tight uploading process, the UPLOAD_COMPLETE_DATA event (Flash Player 9.0.28.0). This event fires after the COMPLETE event and contains an important piece of information. The data property of the DataEvent contains the raw data returned from the server after a successful file upload. Finally, a way to return from the server information about the file and/or process. This is especially useful if during the upload process you need to do additional things like create a database record and then return the new database id, or possibly put the file in a different path based on the user, and return the path where the file exists back to the client.

Here's a quick sample of implementing the new event in Flex and also a Coldfusion and PHP script to upload a file and then output and return data back to the client in a clean consistent fashion.

The Flex code. As you can see, this is a very simple example, you select a file and when the upload has completed the results from the server are output into a text area.

Friday, July 13, 2007

Flex2 FileReference API for Uploading Files

http://renaun.com/blog/2006/06/27/51/

example:http://shigeru-nakagaki.com/flex_samples/FileReference/FileUploadExample2/FileUploadExample2.html

Receiving data in response to file upload in Flex using FileReference

here
from Anand Vardhan 's blog

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())
}