Solved

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

Posted on 2004-09-24
3
594 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

809 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