• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File Upload error JSF tomahawk

 
vijay k vemula
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Thanks to all of you for your previous valuable suggestions.
Currently iam working on file upload functionality using <t:inputFileUpload> in tomahawk.

when i click on "Upload Photos" button iam able to call my backing bean method upLoad()...which has to upload the files to the server. Here is my sample code...

String dynamicDir1 ="/images/acpstg";
UploadedFile uploadedFile = (UploadedFile) uploadFileIterator.next();
InputStream stream = uploadedFile.getInputStream();
if(uploadedFile.getContentType().equals("image/pjpeg"))
{//1
File dir1 = new File(dynamicDir1);
if ( !dir1.exists()) {
dir1.mkdir(); //Create directory
}
dir1.createNewFile();
dir1.canWrite();
dir1.getAbsolutePath();
dir1.listFiles();
String fileName="";
StringTokenizer st = new StringTokenizer(uploadedFile.getName(),"\\");
while(st.hasMoreTokens())
{
fileName=st.nextToken();
}

}
My problem is iam getting the following exception...at the following line in my above code dir1.createNewFile();

R java.io.IOException: The system cannot find the path specified.
[12/18/08 9:43:24:347 CST] 00000021 SystemErr R at java.io.WinNTFileSystem.createFileExclusively(Native Method)
[12/18/08 9:43:24:347 CST] 00000021 SystemErr R at java.io.File.createNewFile(File.java:876)
[12/18/08 9:43:24:347 CST] 00000021 SystemErr R at germania.gwp.beans.PhotosUploadBean.upLoad(PhotosUploadBean.java)
[12/18/08 9:43:24:347 CST] 00000021 SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Any help will be highly appreciated.

Thanks in Advance
Vijay
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

if(uploadedFile.getContentType().equals("image/pjpeg"))

That's an IE-proprietary mimetype. The valid mimetype is "image/jpeg". Don't make your webapp that dependent on a single webbrowser which doesn't respect the web standards at all. Rather check if the content type ends with "jpeg", or, maybe better, starts with "images". There are more image types than only jpg.

dir1.mkdir(); //Create directory

It only tries to create the last directory. Maybe you need mkdirs() instead? Those methods returns a boolean by the way. Have you checked it?

dir1.createNewFile();
dir1.canWrite();
dir1.getAbsolutePath();
dir1.listFiles();

All of those things makes no sense. Leave them away. Just write to file using FileOutputStream.

String fileName="";
StringTokenizer st = new StringTokenizer(uploadedFile.getName(),"\\");
while(st.hasMoreTokens())
{
fileName=st.nextToken();
}

}

As you're using Tomahawk, you have Commons IO API in your classpath. Rather use FileNameUtils#getName(). Also see http://commons.apache.org/fileupload/faq.html#whole-path-from-IE
[ December 18, 2008: Message edited by: Bauke Scholtz ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic