• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown

File uploading

Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using validator framework for validation. File uploading functionality is working fine. I have specified max file size in config file. If file size is greater than specified size then how to display proper error like "file should not be greater than xyz size".

Please suggest how to solve this problem.

Thanking you in an anticipation.
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, it's important to understand that the max file size you specify in the struts-config.xml file exists mainly for protection against denial of service attacks, where someone might try to upload a huge file just to overload your server and make it crash. If a user tries to upload a file larger than the size you specify, Struts simply won't upload the file, and won't populate the property associated with the file. If you try to access it in your Action class, it will simply be null. If the user just doesn't put anything in the file upload text box and presses the submit button, Struts will put a FormFile object in the ActionForm, but the getFileSize() method will return zero.

You could catch this error in the Validation framework by putting a "required" dependency on the file to be uploaded. However, this would give the wrong message. It would tell the user that the file is required, when the actual problem is that the file is too big.

What I'd suggest is just to have your action class check to see if the FormFile object is null. If it is, handle it the way you would any error message generated from an action class: Instantiate an ActionMessages object, add an ActionMessage to it, and call the saveErrors() method. Example:

[ March 09, 2007: Message edited by: Merrill Higginson ]
    Bookmark Topic Watch Topic
  • New Topic