0 Replies Latest reply on Mar 25, 2010 7:01 AM by chieffan

    File Upload using Flex/ColdFusion.  2044 error

    chieffan Level 1

      I am looking for a little more clarity around the file upload using Flex and Cold Fusion.  When I run this using my server I get Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error.


      I did create a regular cfform and had it use my ColdFusion upload form and that worked fine, so I feel good about the upload form. I am starting to think there is a permission error with the Flash Player writing to the folder.  When this is ran, it will show the file being 100% loaded but the complete event is never triggered.  I put alerts to see where it hits and 100 does show at the same time as my error message.  The complete alert never shows.  I also put an alert in my cfm page and it never reaches that page to hit it.  Whether I use an absolute URL or relative path. I have also tried the urlrequestmethod.post and nothing changed.  Thanks in advance.  BTW.  I am using Flex 3.


      This is my mxml file


      <?xml version="1.0" encoding="utf-8"?>




      xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:example="com.example.*" horizontalAlign="center" viewSourceURL="srcview/index.html">









      import com.example.FileDownload


      import mx.controls.Label



      import com.example.FileUpload









      <mx:Label id="title" text="File I/O Example" fontSize="24" fontStyle="bold" />



      <mx:Text id="subtitle" text="From Programming ActionScript 3.0, Chapter 22: Networking and communication" width="100%" textAlign="center" fontSize="12" />



      id="fileDownload" creationComplete="fileDownload.init(downloadProgress, cancelDownload);" />



      <example:FileUpload id="fileUpload" creationComplete="fileUpload.init(uploadProgress, cancelUpload);" />







      <mx:Panel title="Upload File" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">



      <mx:ProgressBar id="uploadProgress" label="" mode="manual" />



      <mx:ControlBar horizontalAlign="right">



      <mx:Button id="startUpload" label="Upload..." click="fileUpload.startUpload();" />



      <mx:Button id="cancelUpload" label="Cancel" click="fileUpload.cancelUpload();" enabled="false" />









      <mx:Panel title="Download File" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">



      <mx:ProgressBar id="downloadProgress" label="" mode="manual" />



      <mx:ControlBar horizontalAlign="right">



      <mx:Button id="startDownload" label="Download..." click="fileDownload.startDownload();" />



      <mx:Button id="cancelDownload" label="Cancel" click="fileDownload.cancelDownload();" enabled="false" />












      here is my coldfusion upload script


      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>

      <cfset currentPath = getCurrentTemplatePath()>
      <cfset currentDirectory = getDirectoryFromPath(currentPath)>
      <cfoutput>This directory is #currentDirectory#</cfoutput>

      <cffile action="UPLOAD" filefield="Filefield" destination="#currentDirectory#" nameconflict="OVERWRITE"/>

      here is the package





      com.example {


      import flash.events.*;


      import flash.net.FileReference;


      import flash.net.URLRequest;


      import flash.net.URLRequestMethod;



      import mx.controls.Button;


      import mx.controls.ProgressBar;


      import mx.core.UIComponent;


      import mx.controls.Alert;



      public class FileUpload extends UIComponent {


      // Hard-code the URL of the remote upload script.


      private const UPLOAD_URL:String = "upload_script.cfm";


      private var fr:FileReference;


      // Define reference to the upload ProgressBar component.


      private var pb:ProgressBar;


      // Define reference to the "Cancel" button which will immediately stop the upload in progress.


      private var btn:Button;



      public function FileUpload() {





      * Set references to the components, and add listeners for the SELECT,

      * OPEN, PROGRESS, and COMPLETE events.



      public function init(pb:ProgressBar, btn:Button):void {


      // Set up the references to the progress bar and cancel button, which are passed from the calling script.


      this.pb = pb;


      this.btn = btn;


      fr =

      new FileReference();

      fr.addEventListener(Event.SELECT, selectHandler);

      fr.addEventListener(Event.OPEN, openHandler);

      fr.addEventListener(ProgressEvent.PROGRESS, progressHandler);



      // fr.addEventListener(Event.COMPLETE, completeHandler);










      * Immediately cancel the upload in progress and disable the cancel button.



      public function cancelUpload():void {


      pb.label =


      btn.enabled =






      * Launch the browse dialog box which allows the user to select a file to upload to the server.



      public function startUpload():void {






      * Begin uploading the file specified in the UPLOAD_URL constant.



      private function selectHandler(event:Event):void {


      var request:URLRequest = new URLRequest(UPLOAD_URL);


      /* request.url = UPLOAD_URL*/

      request.method = URLRequestMethod.POST;








      catch (error:Error){




      ("error uploading")






      * When the OPEN event has dispatched, change the progress bar's label

      * and enable the "Cancel" button, which allows the user to abort the

      * upload operation.



      private function openHandler(event:Event):void {

      pb.label =


      btn.enabled =






      * While the file is uploading, update the progress bar's status and label.



      private function progressHandler(event:ProgressEvent):void {

      pb.label =

      "UPLOADING %3%%";

      pb.setProgress(event.bytesLoaded, event.bytesTotal);













      * Once the upload has completed, change the progress bar's label and

      * disable the "Cancel" button since the upload is already completed.



      private function completeHandler(event:Event):void {


      "in function")

      pb.label =


      pb.setProgress(0, 100);

      btn.enabled =