troubleshooting Question

Exception using Apache FileUpLoad?

Avatar of AntoniRyszard
AntoniRyszard asked on
JSP
17 Comments1 Solution629 ViewsLast Modified:
Hello,

I constructed a basic html page to post several files to a java servlet. In the servlet I am using the apache tool fileupload to accept files, and write these to a folder.  

In the code below the servlet loops through the posted files. I noticed the fileupload method (getName()) returns the complete path of the file on the users hard-drive. For example

c:\windows\desktop\tree.jpg

And I am using to write the files to tomcat\files\

When it comes to writing the file an exception is thrown.

Does anyone think I should be parsen the getName() value to recieve just the file name (tree.jpg) and not the full path c:\windows\desktop\tree.jpg.

I hope this makes sense.

Thanks

Iterator iter = items.iterator();

while(iter.hasNext()){
   FileItem item = (FileItem) iter.next();
   File uploadedFile = new File("/tomcat/files/" + item.getName());
   //item.write(uploadedFile);
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 17 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros