Solved

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

Posted on 2004-09-24
3
608 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

707 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