Package | co.uk.mikestead.net |
Class | public class URLFileVariable |
To add an instance of URLFileVariable to a URLRequest you must first create a URLVariables instance and then set one or more of its properties with a URLFileVariable instance. This URLVariables instance should then be passed to a URLRequestBuilder which can construct the URLRequest with the correct encoding to transport the file(s) to the server.
// Construct variables (name-value pairs) to be sent to sever var variables:URLVariable = new URLVariables(); variables.userImage = new URLFileVariable(jpegEncodedData, "user_image.jpg"); variables.userPDF = new URLFileVariable(pdfEncodedData, "user_doc.pdf"); variables.userName = "Mike"; // Build the request which houses these variables var request:URLRequest = new URLRequestBuilder(variables).build(); request.url = "some.web.address.php"; // Create the loader and use it to send the request off to the server var loader:URLLoader = new URLLoader(); loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError); loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onError); loader.addEventListener(IOErrorEvent.IO_ERROR, onError); loader.addEventListener(Event.COMPLETE, onServerResponse); loader.load(request); function onServerResponse(event:Event):void { trace("Variables uploaded successfully"); } function onError(event:Event):void { trace("An error occured while trying to upload data to the server: \n" + event); }
See also
Property | Defined by | ||
---|---|---|---|
data : ByteArray [read-only]
The contents of the file
| URLFileVariable | ||
name : String [read-only]
The name to be given to the file on the server
| URLFileVariable |
Method | Defined by | ||
---|---|---|---|
URLFileVariable(data:ByteArray, name:String)
Constructor.
| URLFileVariable |
data | property |
data:ByteArray
[read-only]The contents of the file
Implementation public function get data():ByteArray
name | property |
name:String
[read-only]The name to be given to the file on the server
Implementation public function get name():String
URLFileVariable | () | constructor |
public function URLFileVariable(data:ByteArray, name:String)
Constructor.
Parametersdata:ByteArray — The contents of the file to be sent to the server
|
|
name:String — The name to be given to the file on the server, e.g. user_image.jpg
|