Packageco.uk.mikestead.net
Classpublic class URLFileVariable

The URLFileVariable class wraps file data to be sent to the server using a URLRequest.

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.


Example
     // 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

URLRequestBuilder


Public Properties
 PropertyDefined 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
Public Methods
 MethodDefined by
  
URLFileVariable(data:ByteArray, name:String)
Constructor.
URLFileVariable
Property detail
dataproperty
data:ByteArray  [read-only]

The contents of the file

Implementation
    public function get data():ByteArray
nameproperty 
name:String  [read-only]

The name to be given to the file on the server

Implementation
    public function get name():String
Constructor detail
URLFileVariable()constructor
public function URLFileVariable(data:ByteArray, name:String)

Constructor.

Parameters
data: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