I was showing off Adobe AIR (formerly apollo) to a client, trying to create a simple file upload mini app. I followed the documentation, but was constantly getting the following error whenever I tried to upload.

Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error.
	at AIRFileUpload$iinit()
	at _AIRFileUpload_mx_managers_SystemManager/create()
	at mx.managers::SystemManager/::initializeTopLevelWindow()
	at mx.managers::SystemManager/::docFrameHandler()

I finally found the following technote which led me to the missing ingredient:

request.method = URLRequestMethod.POST;


Once I added that my application was working just fine.



Here is the code:

AIRFileUpload.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="150" width="300">
<mx:Script>
   <![CDATA[
         
         import flash.net.FileReference;
         import flash.events.*;

         private var fileRef:FileReference = new FileReference();Çspan style='color: #808080'ÈÇemÈ //Used to hold the file we are uploading
Ç/emÈÇ/spanÈ         private var uploadURL:String = "http://127.0.0.1/projects/air/AirFileUpload/bin/upload.cfm";Çspan style='color: #808080'ÈÇemÈ // URL for server side upload script
Ç/emÈÇ/spanÈ         
         [Bindable]
         private var statusMsg:String = "No file Selected";Çspan style='color: #808080'ÈÇemÈ // Used in status label
Ç/emÈÇ/spanÈ         
         
         /* Activate the OS file selection menu */
         private function selectFile():void {
         
                     try
                     {
                      var success:Boolean = fileRef.browse();
                      fileRef.addEventListener(Event.SELECT, selectHandler);
                     }
                     catch (error:Error)
                     {
                        trace("Unable to browse for files.");
                     
                     }
                  }
         
         
         /* Uploads the file to the server */
         private function uploadFile():void {

                  var request:URLRequest = new URLRequest();
                   request.url = uploadURL;
                   request.method=URLRequestMethod.POST;
         
                try
                   {
                      fileRef.upload(request,"Filedata");
                   fileRef.addEventListener(Event.COMPLETE, completeHandler);
                   statusMsg="Uploading...";
                   }
                   catch (error:Error)
                   {
                   statusMsg = "Unable to upload file.";
                   }
                  }      
   
         
            private function selectHandler(event:Event):void {
               statusMsg = "Selected " + fileRef.name;
               btnUpload.enabled=true;
            }         


            private function completeHandler(event:Event):void
            {
             statusMsg = "File Uploaded";
             btnUpload.enabled=false;
            }
      

   ]]>
</mx:Script>

   <mx:VBox width="100%" height="100%">
      <mx:Form>
         <mx:FormHeading label="Uploading a file to a remote server" />
   
         <mx:FormItem label="1.">
            <mx:Button click="selectFile()" label="Select A file" horizontalCenter="0" id="btnSelect" />
         </mx:FormItem>
         <mx:FormItem label="2.">
            <mx:Button click="uploadFile()" label="Upload" horizontalCenter="0" enabled="false" id="btnUpload" />
         </mx:FormItem>
      </mx:Form>
      <mx:Label text="Status: {statusMsg}" />
   </mx:VBox>

</mx:WindowedApplication>

upload.cfm
<cffile action="upload" filefield="Filedata" destination="#ExpandPath('.')#" nameconflict="OVERWRITE" />

Comments
Jeff's Gravatar Thank you, thank you, thank you! I've been fighting with this for 3 hours tonight. My app works great now! I really appreciate your help.

JD
# Posted By Jeff | 9/10/07 2:07 AM
Y-boy.cn's Gravatar Yeah
" request.method = URLRequestMethod.POST; "

This is important.

Thank you !
# Posted By Y-boy.cn | 9/15/07 11:10 PM
Aditya Bhushan's Gravatar What a saviour this post. I was struggling to get this working for last 2 days.. Thanks buddy... :)
# Posted By Aditya Bhushan | 10/8/07 5:52 AM
pete's Gravatar Thank you, thank you, thank you! I've been fighting with this for 3 hours tonight. My app works great now! I really appreciate your help.
http://www.dir-9.com
# Posted By pete | 11/25/07 2:55 AM
Tapety's Gravatar Thank you, great help. THX.
# Posted By Tapety | 12/24/07 7:00 AM
Yariv Gilad's Gravatar Hi Shlomy
i run a filereference.upload test flex web-application which uploads a file through a coldfusion server.
i’m using flex 3 and coldfusion 9.
i’m also passing parameters in the URLRequest that points to the upload cfm file.
when i run my test using the built-in web server (Jrun) all seems to work just fine
when i run the same test on a coldfusion instance that runs on Apache web server, it throws a I/O Error…
i suspect i’m missing some kind of a configuration i need to perform when moving to a production setup rather then a development environment…
can anyone guide me through this?
does it have to do with security? on the client? on the server?
i’m still running on localhost…

the code is very similar to yours

thank you for your time
cheers
Yariv
# Posted By Yariv Gilad | 10/10/09 6:21 AM
Powered by BlogCFC

HostMySite.com Web Hosting Provided by www.HostMySite.com

Aggregated by fullasagoog.com
[Valid RSS]

Add to Google