commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Cook <>
Subject [commons-file upload] Will not save just the file name
Date Fri, 09 Jan 2004 02:00:01 GMT

I am having a problem with the commons FileUpload package.  It works 
fine on my development work station(Win2k).  I run into a problem with 
Internet Explorer(5.5, 6.0) after I transfer the servlet file to my 
production box(Linux).  Mozilla, Opera, and Safari are all fine, but 
when uploading a file with Internet Explorer it returns the entire 
client side path with the file name.


When uploading the file example.txt the item.getName(); object returns :
C:\dev\store\rpm\5\example.txt as the file name.

I tried the fix posted on :
with out success.

I have included the code and Vital stats below.  Any ideas on what I am 
doing wrong would be great.

<Vital Stats>
Java            : J2SE SDK 1.4.2
Server OS        : Red Hat 9.0     2.4.28
Server Container    : Tomcat 4.1.29
IDE            : Netbeans  3.5.1
Browsers that fail    : Internet Explorer 5.5, 6
Browsers that work    : Mozilla 1.4 Opera 6
Package            :
</Vital Stats>


DiskFileUpload incomingData = new DiskFileUpload();

     boolean isMultipart = FileUpload.isMultipartContent(req);

     if(isMultipart==false)         {return;}

     java.util.List items = incomingData.parseRequest(req);

     // Parse the list of everything but the field names
     java.util.Iterator list = items.iterator();

     // Now that we have a list of ALL of the fields that were POSTed
     // Start a loop to read though the list one at a time.
     while(list.hasNext()) {

         // If it is actually a field then call another method to
         // copy the field value to the aprpreate variable.
         FileItem item = (FileItem);
         if(item.isFormField()) {
             writeToSessionObject(item.getFieldName(), item.getString(),
         }                        // Close the test for form field

     	// If the item is not a field then it is assumed to be a file,
         // and it is written to the disk.
         else {                   // opens else for field type test

         // This should be the file name, but IE returns
         // The entire path
         String itemName = item.getName();

          // Test for and empty file field
             if(itemName.length()<2) {/*orderInfo.FileUploaded=false;*/ }

         else {         // Opens else in readIncommingData

                     // Define the File object that will be used to 
              		    // extract the file.
                     File fullFile = new File(itemName);

                     // This second File object will actually write the 
                     		    // file to the back up dir.  It will put the 
file                  		    // name from the fullFile object
                     File savedFile = new File(getServletContext()

                     // Write the file to disk

                     // Save the name of the file that was uploaded
             	    // in the session object.

                     // Record in the system log that a file was
              	    // uploaded and where it was saved
                     System.out.println("Ok, "+fullFile.getName()
                     +" was writen to:\n"+savedFile.toString());
                 }                           // Closes nested else
              }                              //
           }                                 //


Brian Cook
Variable Data \
Web Services Consultant
Print Time Inc.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message