File Upload/Download
Flex applications support file upload and download using the Flash
Player flash.net.FileReference class.
You can enable the user to download one file at a time, as
well as select and upload one or more files at the same time.
Downloading Files
Use the download() method of a
FileReference object to download a
file. The download() method requires at least one parameter: a URLRequest object. The URLRequest object should point to the URL from
which you want to download the file. Here’s an example that downloads a
file called test.txt:
var fileReference:FileReference = new FileReference();
fileReference.download(new URLRequest("test.txt"));As soon as the download()
method is called, Flash Player will open a dialog prompting the user to
accept the file. The user has complete control over whether to save the
file, where to save the file, and what to name the file. However, by
default, the filename field in the dialog will be filled out with the
name of the file as it exists on the server. If you want to customize
the default filename in the dialog, you can do so with a second
parameter in the download() method.
This is particularly useful when the URL from which the file is
requested is a script that generates the file or proxies the request to
the file. For example, if the URL from which you request the file is
test.cgi, a script that outputs a
text file, you likely will want to use a custom filename rather than
allow it to default to test.cgi.
Here’s an example:
fileReference,download(new ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access