This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes File Upload error JSF tomahawk Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "File Upload error JSF tomahawk" Watch "File Upload error JSF tomahawk" New topic
Author

File Upload error JSF tomahawk

vijay k vemula
Greenhorn

Joined: Dec 17, 2008
Posts: 10
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

Joined: Oct 08, 2006
Posts: 2458

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File Upload error JSF tomahawk