Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now