About file uploading and downloading

The FileReference class lets you add the ability to upload and download files between a client and server. Your users can upload or download files between their computer and a server. Users are prompted to select a file to upload or a location for download in a dialog box (such as the Open dialog box on the Windows operating system).

Each FileReference object that you create with ActionScript refers to a single file on the user's hard disk. The object has properties that contain information about the file's size, type, name, creation date, and modification date. On the Macintosh, there is also a property for the file's creator type.

You can create an instance of the FileReference class in two ways. You can use the following new operator:

import flash.net.FileReference;
var myFileReference:FileReference = new FileReference();

Or, you can call the FileReferenceList.browse() method, which opens a dialog box on the user's system to prompt the user to select a file to upload and then creates an array of FileReference objects if the user selects one or more files successfully. Each FileReference object represents a file selected by the user from the dialog box. A FileReference object does not contain any data in the FileReference properties (such as name, size, or modificationDate) until the FileReference.browse() method or FileReferenceList.browse() method has been called and the user has selected a file from the file picker or until the FileReference.download() method has been used to select a file from the file picker.

NOTE

 

FileReference.browse() lets the user select a single file. FileReferenceList.browse() lets the user select multiple files.

After a successful call to the browse() method, you call FileReference.upload() to upload one file at a time.

You can also add download functionality to your Flash application. The FileReference.download() method prompts end users for a location on their hard disks to save a file from a server. This method also initiates downloading from a remote URL. When using the download() method, only the FileReference.name property is accessible when the onSelect event is dispatched. The rest of the properties are not accessible until the onComplete event is dispatched.

NOTE

 

When a dialog box appears on the end-user's computer, the default location that appears in the dialog box is the most recently browsed folder (if that location can be determined) or the desktop (if the recent folder cannot be determined). The FileReference and FileReferenceList APIs do not let you set the default file location

For information on the functionality and security of the FileReference API, see About FileReference API functionality and security. For an example of an application that uses the FileReference API, see Adding file upload functionality to an application. For a sample source file for this example, FileUpload.fla, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download the Samples zip file and navigate to the ActionScript2.0/FileUpload folder to access this sample.

For information on each method, property, and event of the FileReference API, see FileReference (flash.net.FileReference) and FileReferenceList (flash.net.FileReferenceList) in the ActionScript 2.0 Language Reference.


Flash CS3