Solved

commons fileupload problem: getName() return full path instead of filename alone

Posted on 2004-09-24
3
601 Views
Last Modified: 2012-05-05
I am using the upload file package. The getName() function from FileItem class return full path instead of filename alone. the description in javadoc for this function states that this will only happen in some of the browsers. But i am using explorer. This problem shouldn't happen.
0
Comment
Question by:jeff1919
3 Comments
 
LVL 1

Accepted Solution

by:
manuel2004 earned 250 total points
ID: 12148662
there seems to be a bug in item.getName() as it returns the full path on the client's machine for the uploaded file name, instead of the file name only. To overcome that, I have used a workaround using fullFile.getName().


            File fullFile  = new File(item.getName());  
            File savedFile = new File(getServletContext().getRealPath("/"),
            fullFile.getName());
            item.write(savedFile);


I think this should do the trick
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question