[jboss-user] [JBoss Seam] - Re: File upload to application folder

gemel do-not-reply at jboss.com
Tue Aug 7 04:12:44 EDT 2007


Hello,
I hope you have already found a solution with the FileNotFoundException. Anyway I'm going to tell you how I solved this.

I had the same problem: Upload an image through s:fileupload and save it in anoter location.
Like you I got the FileNotFoundException. 

1- You can't use only the fileName property of s:fileupload  because this fileName doesn't have the directory structure. It just have something like this: bild.jpg
2- You have to locate the directory inside your application (where you want to save your file) with such a code for example:

  | Properties props = System.getProperties(); 
  | String jbossServerHomeUrl = props.getProperty( "jboss.server.home.url");
  | 

Psst: with your debugger, you can browse the properties inside props, and see what you have inside...

3- When you have your URL Please create an URI with it. And then create a file based on you URI

  | URI bckGUri = new URI( jbossServerHomeUrl );                	
  | File ilogBackgroundsFile = new File( bckGUri ); 
  | ilogBackgroundsFile.mkdirs();
  | 

Psst: If you forget the mkdirs(), you will have the FileNotFoudException again!!

4- Then write in your file

  | String imageFileDir = props.getProperty("jboss.server.home.dir") + File.separator + "bild.jpg";
  | FileOutputStream fos = new FileOutputStream( imageFileDir );
  | fos.write( byteArray );
  | 

Please be aware that I told of URL in part 3 but of Directories in part 4
Hope this will help!

Hope


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071462#4071462

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071462



More information about the jboss-user mailing list