Accessibility

Table of Contents

Uploading files to a server from an Adobe AIR application

Monitoring the upload progress

During a file upload process, the amount of data uploaded is relative to the total file size of the file broadcast via a ProgressEvent. The following code shows a simple example of this:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute applicationComplete="startApplication();">
   <mx:Script>
       <![CDATA[
           private var fileRef:FileReference = new FileReference();
           private function startApplication():void {
               fileRef.browse();
               fileRef.addEventListener(Event.SELECT,selectHandler);               
               fileRef.addEventListener(ProgressEvent.PROGRESS,progressHandler);
           }
           private function selectHandler(event:Event):void {
               var thisFileRef:FileReference = FileReference(event.target);
               var uploadURL:URLRequest = new URLRequest("http://www.o2apps.net/fileUpload.pl");
               thisFileRef.upload(uploadURL);
           }
           private function progressHandler(event:ProgressEvent):void {
               trace(event.bytesLoaded+" out of "+event.bytesTotal+" have been uploaded");
           }
       ]]>
   </mx:Script>
</mx:WindowedApplication>

The progressHandler function above is passed an object of type ProgressEvent whose properties, bytesLoaded and bytesTotal, can be used to provide textual or visual feedback to users depicting how much of their files remain to be uploaded.