commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Kindler <...@kruescho.de>
Subject [FileUpload] no possibility to stop upload in case of a FileSizeLimitExceededException?
Date Thu, 06 Mar 2008 16:15:49 GMT
Hello,

I'm using FileUpload 1.3 with Tomcat 6.0.16 and JDK 1.6.0_04 on Windows XP.

I changed org.apache.commons.fileupload.FileUploadBase and 
org.apache.commons.fileupload.MultipartStream as described here:
https://issues.apache.org/jira/browse/FILEUPLOAD-145

But the problem is when uploading in file large than the max. size set 
with ServletFileUpload.setFileSizeMax() an exception is thrown but it 
takes a while (I assume until the complete file is uploaded) until the 
request is forwarded to the error.jsp.

What can I do to stop the upload immediatly when the file size limit is 
reached?

See code and stacktrace below.

Christian


----- doPost() method from my upload servlet ----

public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {

	if (ServletFileUpload.isMultipartContent(request)) {
		ServletFileUpload upload = new ServletFileUpload();
		upload.setFileSizeMax(10000000);

		try {
			FileItemIterator iter = upload.getItemIterator(request);
			while (iter.hasNext()) {
				FileItemStream item = iter.next();
				if (!item.isFormField()) {
					String fileName = new File(item.getName()).getName();
					Streams.copy(item.openStream(),
						new FileOutputStream("C:/Temp/" + fileName), false);
				}
			}
		} catch (Exception e) {
			log("ERROR DURING UPLOAD", e);
			RequestDispatcher dispatcher =
				getServletContext().getRequestDispatcher("/error.jsp");
			dispatcher.forward(request, response);
		}
	}
}


---- stack trace ----

org.apache.commons.fileupload.FileUploadBase$FileUploadIOException
	at 
org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:655)
	at 
org.apache.commons.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:71)
	at 
org.apache.commons.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:128)
	at java.io.FilterInputStream.read(Unknown Source)
	at org.apache.commons.fileupload.util.Streams.copy(Streams.java:94)
	at org.apache.commons.fileupload.util.Streams.copy(Streams.java:64)
	at de.test.Test.doPost(Test.java:45)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
	at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
	at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Unknown Source)
Caused by: 
org.apache.commons.fileupload.FileUploadBase$FileSizeLimitExceededException: 
The field file1 exceeds its maximum permitted  size of 10000000 characters.
	at 
org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:649)
	... 20 more

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message