File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes uploaded file size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "uploaded file size" Watch "uploaded file size" New topic

uploaded file size

fang eve

Joined: Jun 22, 2006
Posts: 26
how can i set the maximum file size for uploading. i running on tomcat.
abhijit Ohal
Ranch Hand

Joined: Mar 10, 2006
Posts: 64
if you are getting byte stream of uplodings. then from it you can calculate it's size
Mike Noel
Ranch Hand

Joined: Dec 15, 2005
Posts: 108
There might be a tomcat setting for limiting this but it seems easier to limit the upload size in your app. It is likely that you have a loop that is reading bytes from the incoming stream. You can just keep a sum of the size you've read so far and then throw an error if the size is greater than your threshold.

An advantage of doing this yourself instead of having tomcat do it is that your app is a little more portable. You can move it to another servlet container without worrying about the upload size limiting.

Mike Noel
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
All file upload packages I've seen had a parameter that let you limit the size (e.g., Jakarta Commons FileUpload does). Which one are you using? Or does Tomcat have one built in these days?
I agree. Here's the link:
subject: uploaded file size
jQuery in Action, 3rd edition