Flash 8 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > FileReference (flash.net.FileReference) > upload (FileReference.upload method) | |||
public upload(url:String) : Boolean
Starts the upload of a file selected by a user to a remote server. Flash Player can upload files of up to 100 MB. You must call FileReference.browse() or FileReferenceList.browse() before calling this method.
Listeners receive events to indicate the progress, success, or failure of the upload. Although you can use the FileReferenceList object to let users select multiple files to upload, you must upload the files one by one. To do so, iterate through the FileReferenceList.fileList array of FileReference objects.
The file is uploaded to the URL passed in the url parameter. The URL must be a server script configured to accept uploads. Flash Player uploads files using the HTTP POST method. The server script that handles the upload should expect a POST request with the following elements:
Content-Type element of multipart/form-dataContent-Disposition element with a name attribute set to "Filedata" and a filename attribute set to the name of the original fileHere is a sample POST request:
Content-Type: multipart/form-data; boundary=AaB03x --AaB03x Content-Disposition: form-data; name="Filedata"; filename="example.jpg" Content-Type: application/octet-stream ... contents of example.jpg ... --AaB03x--
You can send data to the server with the upload() call by appending parameters to the URL.
Note: If your server requires user authentication, only SWF files running in a browser--that is, using the browser plug-in or ActiveX control--can provide a dialog box to prompt the user for a user name and password for authentication, and only for downloads. For uploads that use the plug-in or ActiveX control, and for uploads and downloads that use the stand-alone or external player, the file transfer fails.
When using this method, consider the Flash Player security model:
For more information, see the following:
Availability: ActionScript 1.0; Flash Player 8
url:String - The URL of the server script configured to handle upload through HTTP POST calls. The URL can be HTTP or, for secure uploads, HTTPS.
You can send data to the server with the upload() call by appending parameters to the URL; for example, http://www.myserver.com/upload.cgi?userID=jdoe
On some browsers, URL strings are limited in length. Lengths greater than 256 characters may fail on some browsers or servers.
Boolean - A value of false in any of the following situations:
FileReference.browse() has not yet been successfully called on this object, or if FileReferenceList.browse() has not yet been successfully called with this object in its filelist array.url parameter is of the incorrect type or format.The following example shows an implementation of the upload() method by first prompting the user to select a file to upload, then handling the onSelect and onCancel listeners, and finally handling the results of the actual file upload.
import flash.net.FileReference;
var allTypes:Array = new Array();
var imageTypes:Object = new Object();
imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";
allTypes.push(imageTypes);
var listener:Object = new Object();
listener.onSelect = function(file:FileReference):Void {
trace("onSelect: " + file.name);
if(!file.upload("http://www.yourdomain.com/yourUploadHandlerScript.cfm")) {
trace("Upload dialog failed to open.");
}
}
listener.onCancel = function(file:FileReference):Void {
trace("onCancel");
}
listener.onOpen = function(file:FileReference):Void {
trace("onOpen: " + file.name);
}
listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
}
listener.onComplete = function(file:FileReference):Void {
trace("onComplete: " + file.name);
}
listener.onHTTPError = function(file:FileReference):Void {
trace("onHTTPError: " + file.name);
}
listener.onIOError = function(file:FileReference):Void {
trace("onIOError: " + file.name);
}
listener.onSecurityError = function(file:FileReference, errorString:String):Void {
trace("onSecurityError: " + file.name + " errorString: " + errorString);
}
var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
fileRef.browse(allTypes);
browse (FileReference.browse method), browse (FileReferenceList.browse method), download (FileReference.download method), fileList (FileReferenceList.fileList property)
Version 8
 
RSS FEED | SEND ME AN E-MAIL WHEN COMMENTS ARE ADDED TO THIS PAGE | COMMENT REPORT
CURRENT PAGE: HTTP://LIVEDOCS.ADOBE.COM/FLASH/8/MAIN/00002225.HTML
Comments