commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Cook <bc...@printtime.com>
Subject Re: FileUpload - read timed out / stream ended unexpectedly
Date Tue, 08 Jul 2003 14:53:08 GMT
It sounds like the file attachment fields in your HTML are being left 
blank.  I.E. the user is clicking the submit button with out attaching a 
file.  This returns the file parameter(or item) as blank and throws a 
FileUploadException.

You will need to throw in a condition to check to see if the file name 
is blank and if so not call the method that does the uploading.

Example:

    // Read the parameter/item that should hold the file name
    String itemName = item.getName();
    // Check to see if the file name is blank.
    // for some reason doing an if compare to null did not work for
    // me
    if(itemName.length()<2)
    {System.err.println("Oppsss no file to upload");}
    else
    {			// Open else in readParam method
         System.out.println("If triggered");
         File fullFile = new File(itemName);
         File savedFile = new 	 
File(getServletContext().getRealPath("/"),fullFile.getName());
         item.write(savedFile);
         System.out.println("Ok, the file should have been written 
somewhere....");
    }  			// Close else in readP


Mime
View raw message