tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Szynol <>
Subject Re: FileUploadBase$IOFileUploadException
Date Thu, 02 Sep 2010 03:27:19 GMT

Hey, Chris,

I checked the temp directory in and also by adding this line 
to the the ContextListener class:

         System.out.println("Temp dir: "
                 + (event.getServletContext()

The latter is a subdirectory of the former; Tomcat has read/write access 
to both places.

I do create a temporary local copy of the image on disk (by using native 
Java IO classes), so I am able to access the file system without a 
problem (ultimately, the images are stored in a database). It looks like 
fileupload is meant to store a temporary version of the image during the 
upload, presumably to minimize memory usage.  This is where the fail is 
happening, if the image exceeds the threshold size.  I've monitored both 
temporary directories during the upload, and indeed nothing is being 
written to them.

I guess I can increase the threshold size to a higher value to prevent 
the exception by avoiding the file system write altogether, but I worry 
that if the application has many users uploading large images 
concurrently, this set up will quickly lead to fatal out of memory 
errors. :(

I've sent an inquiry to the apache commons user mailing list.  I will 
follow up here when I hear back.

Thanks again for all your advice.


On 9/1/10 10:25 PM, Christopher Schultz wrote:
> Hash: SHA1
> Paul,
> On 9/1/2010 6:58 PM, Paul Szynol wrote:
>> Ah, now I see what you mean.  So the reason the exception isn't being
>> thrown when I increase the threshold value is that the image isn't being
>> written to disk in the first place.  That makes more sense.  But the odd
>> part of it (in my configuration, at least) is that the file permissions
>> do allow fileupload to write the, I guess I still don't
>> understand what's causing the exception.
> I'm reading this:
> Are you calling factory.setRepository(File)?
> If not, you're getting whatever the default is, which is
> System.getProperty(""), which might actually be "/" in
> your case.
> You should probably be doing something like this:
> ServletContext app = request.getServletContext();
> factory.setRepository((File)app.getAttribute("javax.servlet.context.tempdir"));
> ServletFileUpload upload = new ServletFileUpload(factory);
> ...
> This will allow commons-fileupload to use the spec-defined scratch
> directory for files your webapp needs to write. Be aware that the spec
> makes no statements about how much stuff you can shove into that
> directory, so some containers may limit you in some way (I don't believe
> Tomcat has any such limits, but YMMV).
> Good luck,
> - -chris
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla -
> iEUEARECAAYFAkx/CwgACgkQ9CaO5/Lv0PC9SgCXfnK0xldzZFPal+Masbn6yM3u
> SQCeK1ku59wniXGJupko/2bclOVkyjI=
> =wtBx
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message