• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts & Commons File Upload & maxFileSize

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found some strange behavior when uploading multiple files through a web form using, multiple instances org.apache.struts.upload.FormFile . As you may, or may not know, under the hood Struts uses a CommonsMultipartRequestHandler to process forms of type multipart/form-data, and this class is essentially a wrapper around the Commons File Upload classes that do the work. The Struts config has a property on the controller tag called "maxFileSize". All Struts documentation suggests that this is the maximum file size that can be uploaded, and when uploading one file the behavior is exactly as you would expect - MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED gets set to true, etc, etc. The problem arises when uploading multiple files. The result is that the "maxFileSize" parameter ends up applying to the combined size of all the files. Given the documentation and the name of the property "maxFileSize", I would think it would be much more logical (and useful) if the max size applied to each individual file. Without going into too much detail, when you trace through the Struts and Commons File Upload code, ultimately the "maxFileSize" is compared to HttpServletRequest.getContentLength() to see if the upload is too big. Obviously this will take into account the combined file sizes, so I wouldn't call this a bug, but I don't think the behaviour makes sense. What are your thoughts?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I came up to the same conclusions.
I'm doing an application with nested beans, where the client can upload one or more file depending on how many documents bean are nested in my Form.
So after a post I go trough the collection of form files to check the size of each file individually.
It works, but I don't know if there is a better way to do this.

What do you think
 
Steve Ford
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think what you have described is the only way to do it. Keep in mind that you will need to set the maxFileSize in the struts config, equal to your "true" max file size (ie. the size you are checking for in your form files) multiplied by the maximum number of allowable uploads. If you don't do this, the controller may kill the form submission before you even get to your code which checkes file sizes.
reply
    Bookmark Topic Watch Topic
  • New Topic