The Image, PDF, and Mail services typically act on a file that has been uploaded to the server. To upload the file to your CF server, use the Util class to run the ColdFusion Upload service. The Util class consists of two elements:
- The UPLOAD_URL constant contains the URL on the ColdFusion server of the Upload service, relative to cf_webroot.
- The extractURLFromUploadResponse() method takes response returned by the Upload service as input and returns the path of the uploaded file on the ColdFusion server.
You use the UPLOAD_URL constant and the extractURLFromUploadResponse() function in the following workflow to upload a file and use the file in a ColdFusion service.
Event flow of the ColdFusion service
Use the ActionScript flash.net.FileReference APIs and the Util.UPLOAD_URL variable to upload an Image, PDF, or mail attachment to the server on which the action has to be performed. The upload URL to supply to the flash.net.FileReferenceAPIs can be constructed as follows in the ActionScript part of the application:
uploadURL.url = "http://"+conf.cfServer+":"+conf.cfPort+"/"+conf.contextRoot+"/"+Util.UPLOAD_URL;
var variables:URLVariables = new URLVariables();
variables.serviceusername = conf.serviceUserName;
variables.servicepassword = conf.servicePassword;
uploadURL.data = variables;
Here, specify "conf.cfServer", "conf.cfPort" and "conf.ContextRoot" in the <cf:Config> tag. Specify "conf.ContextRoot" only if ColdFusion is deployed as a J2EE application.
Note: The ActionScript FileUpload functionality is out of the scope for this feature hence it is not explained in detail, but an example of the usage is provided in code in MAIL class section. For further information on FileUpload functionality see the ActionScript documentation.
- Once the file is uploaded, the server returns an XML response containing URL of the uploaded file. Use the Util class function extractURLFromUploadResponse() to extract the URL from the XML
- Use the file URL in the source attribute of the service tags.
When the required service tag attributes are set, run the service action by calling the following method:
- If the action succeeds, the server returns the result. If there is an exception, it returns the fault. Handle the ResultEvent and FaultEvent objects in the service-specific result handler and fault handler that you specify in the service tag, or in global handlers that you specify in the <cf:config>. The ResultEvent object contains the URL of the File on which the operations have been performed. Users can save this file by downloading it on their machine or rendering it in the application. The FaultEvent object contains the exception details that occurred on the server while performing the operation.
For granular control over proxy classes, you can get hold of the underlying RemotObject by using getRemoteObject() method on the proxy class object. For example, for <cf:Mail id="mailId">, you can get it using the following code in ActionScript.
|var mailobject:RemoteObject = mailId.getRemoteObject();|