Flex download files

3.7k views Asked by At

I want to download a file in flex. Here is my desired flow

  • User clicks "view"
  • Code goes to backend and get the file as an array of bytes
  • bytes sent from java to flex via a callback
  • flex then opens dialog and user decides where to save the file

Unfortunately the last part is not on a user event but on the callback from the server. When I call new FileReference().save(...) it tells me this.

An alternative could be

  • User clicks "view"
  • Flex shows user the dialog and user chooses where to save file
  • Flex goes to backend requesting bytes of file
  • bytes sent to flex and data is saved.

For this approach I am unsure how I can make the save asynchronous from the dialog.

Does anyone have any ideas on how I can approach this? Basically I want the user to save a file but the data but come from an array of bytes from the backend

Thanks

3

There are 3 answers

4
Sagar Rawal On BEST ANSWER

FileReference.save() method is not used when you want to save the result.. this method is called only when the mouse or keyboard event occurs. so my advice to you that don't use this method. You can use that method in other way like save the file using JAVA in on back end side. and the method will return you the path of that. you just need to create a URLRequest and call the navigateToURL method. as i have given below.

var path:String = e.result.toString();
var urlRequest:URLRequest = new URLRequest(path);
navigateToURL(urlRequest,"_blank");

Have a Nice Day....

0
Emin A. Alekperov On
1
Ngo Y-An On

How can I download a file from an FTP site (not HHTP). I can't use URLRequest for that. I found some infos about using the socket, but all of them are for UPLOADING. I need to DOWNLOAD