Paul Szynol
Wed, 01 Sep 2010 20:27:55 -0700
Hey, Chris,I checked the temp directory in catalina.sh and also by adding this line to the the ContextListener class:
System.out.println("Temp dir: "
+ (event.getServletContext()
.getAttribute("javax.servlet.context.tempdir"))
.toString());
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. Best, Paul On 9/1/10 10:25 PM, Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE----- 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 file...so, I guess I still don't understand what's causing the exception.I'm reading this: http://commons.apache.org/fileupload/using.html Are you calling factory.setRepository(File)? If not, you're getting whatever the default is, which is System.getProperty("java.io.tmpdir"), 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 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEUEARECAAYFAkx/CwgACgkQ9CaO5/Lv0PC9SgCXfnK0xldzZFPal+Masbn6yM3u SQCeK1ku59wniXGJupko/2bclOVkyjI= =wtBx -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org