I have a flex/lcds/java application that attempts to download a zip file called 
GeneratedTestProject.zip (using FileReference in the Flex app) that I generate 
at runtime on the server (in the Java app). The zip file is generated fine, but 
the following error is thrown by the Flash Player when I click the save button 
of the file download dialog. 


Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error.
      at download::FileDownload/init()
      at tools::CodeGeneratorView/downloadFile()
      at tools::CodeGeneratorView/processResultHandler()
      at tools::CodeGeneratorView/___CodeGeneratorView_Operation1_result()
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at 
mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
      at 
mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()
      at mx.rpc::Responder/result()
      at mx.rpc::AsyncRequest/acknowledge()
      at NetConnectionMessageResponder/resultHandler()
      at mx.messaging::MessageResponder/result()


****Note: I am able to download a separate zip file (CodeGenerator.zip) that 
already exists on the server before the app starts up and was not generated at 
runtime. So it seems as though the download script and the permissions are 
setup correctly, but I am missing something. Please help. Thanks!




Code Snippet of the caller 
-------------------------------
private var zipToDownload:String = 
"http://127.0.0.1:80/toolkit/codegen/GeneratedTestProject.zip";;
                        private var codegenZip:String = 
"http://127.0.0.1:80/toolkit/codegen/execute/CodeGenerator.zip";;


private function downloadFile():void
                        {
                                var fileDownload:FileDownload = new 
FileDownload();
                                fileDownload.init(zipToDownload);
                                fileDownload.startDownload(projectName,false);
                        }

private function downloadCodegenZip():void
                        {
                                var fileDownload:FileDownload = new 
FileDownload();
                                fileDownload.init(codegenZip);
                                fileDownload.startDownload(projectName,true);
                        
                        }




FileDownload.as
---------------------------
package download {  
    import flash.events.*;
    import flash.net.FileReference;
    import flash.net.URLRequest;
    
    import mx.controls.Button;
    import mx.controls.ProgressBar;
    import mx.core.UIComponent;
    import mx.rpc.remoting.RemoteObject;  
  
    public class FileDownload extends UIComponent {  
  
                private var projectName:String;
        public var DOWNLOAD_URL:String;  
        private var fr:FileReference;  
        // Define reference to the "Cancel" button which will immediately stop 
the download in progress.  
        private var btn:Button; 
        private var ro:RemoteObject; 
        public var downloadCodegen:Boolean;
  
        public function FileDownload() {  
  
        }  
  
        /** 
         * Set references to the components, and add listeners for the OPEN, 
         * PROGRESS, and COMPLETE events. 
         */  
        public function init(dURL:String):void {  
            ro = new RemoteObject(); 
            ro.destination = "codeGenService";
            
            // Set up the references to the progress bar and cancel button, 
which are passed from the calling script.  
            this.btn = btn;  
  
            DOWNLOAD_URL = dURL;  
  
            fr = new FileReference();  
            fr.addEventListener(Event.COMPLETE, completeHandler);  
            fr.addEventListener(Event.CANCEL, cancelHandler);  
        }  
                
                public function cancelHandler(event:Event):void {  
            
            ro.cleanUp(projectName);
        }  
  
  
        /** 
         * Immediately cancel the download in progress and disable the cancel 
button. 
         */  
        public function cancelDownload():void {  
            fr.cancel();  
            btn.enabled = false;  
            
        }  
  
        /** 
         * Begin downloading the file specified in the DOWNLOAD_URL constant. 
         */  
        public function 
startDownload(projectName:String,downloadCodegen:Boolean):void 
        {
                this.projectName = projectName;  
                this.downloadCodegen = downloadCodegen;
            var request:URLRequest = new URLRequest(); 
            request.url = DOWNLOAD_URL;  
            
            if(downloadCodegen)
            {
                fr.download(request);  
            }
            else
            {
                fr.download(request,projectName+".zip");  
            }
            
            
            var succeed:Function = function(){};
        }  
        
        /** 
         * Once the download has completed, change the progress bar's label and 
         * disable the "Cancel" button since the download is already completed. 
         */  
        private function completeHandler(event:Event):void {  
            
                
                if(!downloadCodegen)
                {
                        ro.cleanUp(projectName);
                }
        }  
    }  
}














Reply via email to