Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

uploaded file size

 
fang eve
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i set the maximum file size for uploading. i running on tomcat.
 
abhijit Ohal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are getting byte stream of uplodings. then from it you can calculate it's size
 
Mike Noel
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic