Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

How to trap SizeLimitExceededException with apache FileUpload?

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application that allows people to submit multiple files via the web. I'm using a jQuery multiple file upload
plugin on the front-end and I'm using Apache's FileUpload on the backend in my servlet.

I'm running into a problem where if the user tries to upload a file that exceeds the maximum size, I get an exception
and I can't seem to trap it. That means I can't display a meaningful error back to the user.

I've done some Google searches and found some code that looks like it may work, but it's way too complex for me
to even begin understanding and most of it seems to involve either Struts, myFaces or Spring, none of which I'm
currently using.

Any ideas on how I can gracefully notify the user that the file is too large to upload?

This is (part of) the stack trace I get:



The error occurs when I try to do this:



I try to catch it as follows


but it isn't caught.

Here's more complete code:


 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you have not provided your complete code (which is probably a good thing), it is a little hard to determine what the problem is.

Could you please indicate which of those lines you provided is line 46 in your real code? And what is the code at line 258 in your real code?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to appropriate forum.
 
K DeLucia
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is line 46:

List<FileItem> fileItems = parseRequest(request, response);
(line 4 above)

And this is line 258:
fileItems = upload.parseRequest(request);
(line 62 above)

So, when it does the parse, it generates the exception.

Thanks!
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure it is not catching it? Did you try it in the debugger or carefully examine the log output?

What exactly happens when the size limit is exceeded? It looks like you are just returning like normal but would then get a null pointer because your fileItems would be null.

I plugged your catch blocks into my working file upload's try and it caught just fine on the first catch:

 
K DeLucia
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it again, and made a few changes and I got it to the point where it does catch it, but not in the way I expected. Usually I can catch the error and handle it somehow and return gracefully to the user. In this case, it catches the exception, but there doesn't seem to be any way to give the user back their session variables, or recover their data. The best I can do it present the user with the error and the web form that is missing all the text they entered. I'll have to work at it some more I guess. Maybe if I move the upload fields to a separate form and submit them separately from the rest of the form I can work with that somehow.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have the same problem with you, that means if I attach big file size, then all the data filled on the form is lost.

If you have resolved your pb, could you share it with me, please? Thanks.

Regards,
Hoc NGUYEN THANH (thanh.hoc@gmail.com)
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi nguyen Thanh Hoc and welcome to Javaranch!

It might be a good idea to start a new thread with the exact problem you have (with your code)
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did anybody else find a solution to solve this problem?

 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any additional clue?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can catch this

 
Why is the word "abbreviation" so long? And this ad is so short?
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic