You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Harshad Oak <ha...@hotpop.com> on 2003/08/25 13:03:26 UTC

fileupload name issue

Hello,

I am trying to use the FileUpload 1.0 component to upload three files from an HTML page. I am submitting an HTML form to a JSP page.

The HTML is as follows:
    <FORM name="filesForm" action="ProcessFileUpload.jsp"
    method="post" enctype="multipart/form-data">
        File 1:<input type="file" name="file1"/><br/>
        File 2:<input type="file" name="file2"/><br/>
        File 3:<input type="file" name="file3"/><br/>
        <input type="submit" name="Submit" value="Upload Files"/>
    </FORM>

In the JSP I have a statement (fi is a reference to org.apache.commons.fileupload.FileItem):

    System.out.println("NAME: "+fi.getName()); 

Strangely enough, if I submit the form using Opera browser version 7.11, the output of the System.out in the JSP is just the <fileName>. However on trying to submit it using Internet Explorer 5.5, the output is the entire path eg: D:/<directoryname>/<filename>

Is this a known issue and what is the solution for it? I just need the name and not the entire path to the file. I found a possible workaround in an onjava.com article. However if this bug has been fixed in the latest CVS copy, I could pick that up.

thanks,
harshad

Re: fileupload name issue

Posted by Brian Cook <bc...@printtime.com>.
I believe this is a known issue.  I have run into this same issue 
before, and O'REILLY noted it on their examples site.

http://www.onjava.com/pub/a/onjava/2003/06/25/commons.html?page=3

I am not sure how to correct it in JSP  .  With servlets I include the 
following code to define the path.

String itemName = item.getName();   // Read in the name with the path
File fullFile = new File(item.getName());
File savedFile = new 
File(getServletContext().getRealPath("/"),fullFile.getName());
item.write(savedFile);