You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Daryl Stultz <da...@6degrees.com> on 2003/07/08 15:49:13 UTC

FileUpload - read timed out / stream ended unexpectedly

Hi folks, I'm getting the following errors using the final release of
commons upload:

org.apache.commons.fileupload.FileUploadException: Processing of
multipart/form-data request failed. Stream ended unexpectedly
	at
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:429)

org.apache.commons.fileupload.FileUploadException: Processing of
multipart/form-data request failed. Read timed out
	at
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:429)

I'm using Tomcat 4.1.24 with an SSL connection. The problem occurs in both
Netscape 4.7 and IE 6.0. The client machine exhibiting the problem is an
old Windows 9x machine (P2 400, I think). The network is a DSL with a
proxy server in the middle. The page with the problem has a lot of form
fields on it (500) including 3 upload fields. The errors do not coincide
with an actual upload. The upload fields aren't used too much.

The page works fine with a faster machine and a good network connection.

This particular page (on this client) worked fine before adding the upload
controls (and switching the form encoding type to multi-part).

Can you give me some clue as to why this is happening? Is the client
machine too slow? The network too slow? Is SSL messing it up? Is there
some problem with so many form fields on a multi-part form? Is there some
way to configure FileUpload to wait longer (longer timeout)?

Thanks for the help.

Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com


Re: FileUpload - read timed out / stream ended unexpectedly

Posted by Daryl Stultz <da...@6degrees.com>.
Brian Cook <bc...@printtime.com> writes:
>	3. If you dont think this is the problem I would set it up an unparsed 
>inputStream to write to a file on the box the does work, and the one 
>that does not.  This would let you compare the data the two boxes are 
>sending to the servlet container, and isolate if the problem is with the 
>server configuration or the code.

Sounds like a good approach.
>
>Other than that I am out of ideas.  I would be interested to hear how 
>the issue is resolved since it sounds like we are doing similar work.

I'm afraid the client probably will not want to pay for the above
analysis. I'll probably put the actual upload controls on a different page
since the main form gets more usage and was working fine before adding the
upload controls.

Thanks for the help.


Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com


Re: FileUpload - read timed out / stream ended unexpectedly

Posted by Daryl Stultz <da...@6degrees.com>.
"Jakarta Commons Users List" <co...@jakarta.apache.org> writes:
>Daryl
>
>Even if the file is cached if there is a file attach input field in a 
>page that is not filled in. It will return a blank value that will cause 
>a FileUpLoadException
>
Every time? As I mentioned, it never fails except for this one machine. I
can POST the page all day (with or without upload) on my development
machine and it works fine.
>
>Try making the following change:
>
Referring to my previous example code, the error is thrown on the second
line (DiskUpload.parseRequest). This is before the iteration and the
location you suggested I change. I don't see how your change can prevent
an error that occurs in earlier code.

Thanks for the suggestion.

Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com


Re: FileUpload - read timed out / stream ended unexpectedly

Posted by Brian Cook <bc...@printtime.com>.
Daryl

Even if the file is cached if there is a file attach input field in a 
page that is not filled in. It will return a blank value that will cause 
a FileUpLoadException

Try making the following change:
Original	
    else {
 > 		// save item to a HashMap for later processing
 > 		fileUploadItems.put(item.getFieldName(), item);
 > 	}


Changed
    else {				// Opens else
	   //This if tests to see if a file name was returned
	   // if a file name was retuned then
	   // fileUploadItems is called to read it.	
	
	   if((itme.getName).length()>2){  // Opens if

 > 	   // save item to a HashMap for later processing
 > 	   fileUploadItems.put(item.getFieldName(), item);
 > 		}			// Closes if
 > 	}				// Closes else



 > "Jakarta Commons Users List" <co...@jakarta.apache.org> writes:
 >
 >>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.
 >>
 >
 > The page works fine (on my development setup and most produciton 
machines)
 > without uploading anything. My framework "caches" the uploads for later
 > processing. Here's my parsing code (within a wrapper of the request):
 >
 > DiskFileUpload upload = new DiskFileUpload();
 > List items = upload.parseRequest(this, memoryLimit, fileSizeLimit,
 > savePath); // this line fails occasionally
 > Iterator iter = items.iterator();
 > while (iter.hasNext()) {
 > 	FileItem item = (FileItem) iter.next();
 > 	if (item.isFormField()) {
 > 		String key = item.getFieldName();
 > 		String value = item.getString();
 > 		setParameter(key, value, false);
 > 	} else {
 > 		// save item to a HashMap for later processing
 > 		fileUploadItems.put(item.getFieldName(), item);
 > 		}
 > 	}
 >
 > It's the second line that is failing (when it does, which is never unless
 > you happen to be on this one problem machine).
 >
 > Do you see a place in here where the solution you suggested could be
 > applied?
 >
 > Thanks for the help.
 >
 >
 > Daryl Stultz
 > _____________________________________
 > 6 Degrees Software and Consulting, Inc.
 > http://www.6degrees.com
 > mailto:daryl@6degrees.com
 >
 >
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
 > For additional commands, e-mail: commons-user-help@jakarta.apache.org
 >
 >



Re: FileUpload - read timed out / stream ended unexpectedly

Posted by Daryl Stultz <da...@6degrees.com>.
"Jakarta Commons Users List" <co...@jakarta.apache.org> writes:
>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.
>
The page works fine (on my development setup and most produciton machines)
without uploading anything. My framework "caches" the uploads for later
processing. Here's my parsing code (within a wrapper of the request):

DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(this, memoryLimit, fileSizeLimit,
savePath); // this line fails occasionally
Iterator iter = items.iterator();
while (iter.hasNext()) {
	FileItem item = (FileItem) iter.next();
	if (item.isFormField()) {
		String key = item.getFieldName();
		String value = item.getString();
		setParameter(key, value, false);
	} else {
		// save item to a HashMap for later processing
		fileUploadItems.put(item.getFieldName(), item);
		}
	}

It's the second line that is failing (when it does, which is never unless
you happen to be on this one problem machine).

Do you see a place in here where the solution you suggested could be
applied?

Thanks for the help.


Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:daryl@6degrees.com


Re: FileUpload - read timed out / stream ended unexpectedly

Posted by Brian Cook <bc...@printtime.com>.
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