• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1588
  • Last Modified:

File download problem -- Error #2044: Unhandled IOErrorEvent:

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);
      		}
        }  
    }  
}

Open in new window

0
jrwalker2
Asked:
jrwalker2
  • 3
  • 2
1 Solution
 
jrwalker2Author Commented:
One  important thing that I forgot to mention was that everything works fine locally, but not online
0
 
Developer2010Commented:
it is a common problem or what (Security Sandbox Issues with Flex)

i have the same error also , if i closed my flash builder i get the same error but when the application try to connect to the database i posted to qustions and no body answers , also i just found in adobe flex forum someone have the same error , i posted 2 times and then win i found it i did made my comment like that ,
i think we have to try to solve that problem , lets think all in it ,her is  my post was in adobe forum :-

Re: Security Sandbox Issues with Flex/AS3 and AppEngine

Hello ,

 

i have coldfusion 9 and flash builder beta 2 ,

the error for the external hosting is

 

Send failed
Channel.Security.Error error Error #2048: Security sandbox violation: http://www.dcecrak.com/Maine.swf cannot load data from http://localhost:37813/flex2gateway/?hostport=www.dcecrak.com&https=N&id=-1. url: 'http://www.dcecrak.com/flex2gateway/'

 

 

the error if i open my site in my local developement server is

 

Send failed
Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'http://www.dcecrak.com/flex2gateway/'

 

please help i did put the crossdomain.xml and configer defrant endpoint at run time in my flex application

really dont know what to do more i can see blank page if i open that link http://www.dcecrak.com/flex2gateway

or that link too http://localhost:8500/flex2gateway ...

 

and this error dosent happen if i keep running my flash builder and open my project and refresh the dataservice ,

even in the external server , the error gose tell i close my flash builder come again

 

i dont think its crossdomain essue because the comunication with the endpoint are established but whin closeing the flash builder i lose it .

 

the funest thing thet any body except me from any system on the world have the same error but if i open my flash builder he can run the application

and see the data ,, dont know really i am 4 days now in this problem i reinstall all the prodect in ather system , its the same .

please lets solve that problem ,

 

Thanks


and the other guy post was :-

I'm having trouble with an AS3 AMF RemoteObject request that is hosted on App Engine. I have a crossdomain.xml file in the root of the domain, and also one at the remoting endpoint.

 

Here are the contents of the root crossdomain.xml:

 

<?xml version="1.0"?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies ="all"/>
<allow-access-from domain="*.appspot.com"/>
<allow-access-from domain="*.{appid}.appspot.com"/>
<allow-access-from domain="*.{appid}.com"/>
<allow-access-from domain="*.{appid}.org"/>
</cross-domain-policy>

 

I have replaced my application's ID with {appid}. In the endpoint crossdomain.xml, it says the exact same thing, except it omits the <site-control> tag.

 

Loading the swf file and testing it on my machine works just fine... I think that may have something to do with me having the debugger version of Flash Player.

 

When I push it up to App Engine to make it public, other clients access it and get a Client.Error.MessageSend Channel.Security.Error error Error #2048 url: http://05-alpha.latest.{appid}.appspot.com/_rpc/data.

 

I am using Flex 4 beta, and the App Engine Python runtime.

 

Thanks in advance for any help.



so please hope we try work and fined the solution for that ..

0
 
TanLiHaoCommented:
Hello jrwalker2 and Developer2010, I do not think the problems both of you have are the same. I strongly believe jrwalker2's problem is related to the wrong URL given, it may seems that he got it correct but uploading to a server and hosting it on your own computer are not exactly the same thing. Hence you may link to a URL that is not working.

An online link to your application would certainly help, as providing me the code as it is now can't do anything because I can neither test the application for myself(code snippet is not full source code) nor see whether you are doing it correct because the URL seems to be gotten from runtime.

As for Developer2010, I will try to help you with your issue but hang on a moment as I will get to you as soon as I can.


If you like what you said, the issue that both of you have is actually the same, linking all the questions together and discuss would be useful but I do not think that is the case. I will assist both of you separately and see whether things turn out OK first. If it does not, then we consider discussing. This is because like what I said, the issue don't look the same.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jrwalker2Author Commented:
Hi TanLiHao,

Thanks so much for responding to your question. I agree that I believe that my question is not the same as Developer2010. I tried looking into what you said, and tried to put the actual server ip into the url of the file instead of 127.0.0.1:80 but it did not work. Actually, I saw the same behavior as I saw before. Specifically, I was able to download the zip file that was not auto-created at runtime, but I am still able to download the file that was already created on the start of JBoss.

Would be so kind as to send me a direct message with your email address, so that I can send you the full source code please? It is proprietary and would prefer not to post it here. Of course, when we solve the issue, I will definitely grant you full points in this forum for this question. I hope that you agree as this has been a miserable problem for at least 4 days and I don't feel any closer to solving the issue. Also, you have been the only expert to try to help me and my question has been posted for a few days now.  

Thanks so much in advance.
0
 
jrwalker2Author Commented:
Solved!!! The utility that I was using to create the zip file did not work. I imagine that there might have been a stream that was not properly closed. The following code is what I used to create the zip file at runtime.



import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
  private static void zipDir(String zipFileName, String dir) throws Exception {
    File dirObj = new File(dir);
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
    System.out.println("Creating : " + zipFileName);
    addDir(dirObj, out);
    out.close();
  }

  static void addDir(File dirObj, ZipOutputStream out) throws IOException {
    File[] files = dirObj.listFiles();
    byte[] tmpBuf = new byte[1024];

    for (int i = 0; i < files.length; i++) {
      if (files[i].isDirectory()) {
        addDir(files[i], out);
        continue;
      }
      FileInputStream in = new FileInputStream(files[i].getAbsolutePath());
      System.out.println(" Adding: " + files[i].getAbsolutePath());
      out.putNextEntry(new ZipEntry(files[i].getAbsolutePath()));
      int len;
      while ((len = in.read(tmpBuf)) > 0) {
        out.write(tmpBuf, 0, len);
      }
      out.closeEntry();
      in.close();
    }
  }

  public static void main(String[] args) throws Exception {
    zipDir(args[0], args[1]);
  }
}

Open in new window

0
 
TanLiHaoCommented:
Ah, I knew the file is either linked wrongly or doesn't exist. I'm glad you finally solved your problem. :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now