techques
asked on
upload.getFileSizeMax()>10000
why this code does not get the file size and throw exception?
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(isMultipart)
{
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(10000);
factory.setRepository(teFile);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(10000);
if(upload.getFileSizeMax()>10000)
{
response.sendRedirect("error.jsp");
}
will you please produce exception details to resolve the error
ASKER
I tried
catch (SizeLimitExceededExceptio n ex) {
/* The size of the HTTP request body exceeds the limit */
}
But, SizeLimitExceededException cannot be resolved in eclipse
catch (SizeLimitExceededExceptio
/* The size of the HTTP request body exceeds the limit */
}
But, SizeLimitExceededException
your webserver/website has defined max request size limit.
so you can not upload file more than defined size limit.
so you can not upload file more than defined size limit.
ASKER
if not define upload.setSizeMax(10000);
how can the SizeLimitExceededException know when will it throw for more than a defined file size?
how can the SizeLimitExceededException
it is in your configuration file of webserver/ website
if it is not defined there then it will take default size according to your webserver/ website.
if you are using asp.net then it is in web.config like maxrequestlength="12547852 2" (eg no of bytes)
if it is not defined there then it will take default size according to your webserver/ website.
if you are using asp.net then it is in web.config like maxrequestlength="12547852
ASKER
how can I set it
I am using tomcat 6 and servlet.
I am using tomcat 6 and servlet.
>why this code does not get the file size and throw exception?
According to the API the setSizeThreshold method
"Sets the size threshold beyond which files are written directly to disk."
When the threshold is exceeded then the repository is used. From API, the setRepository method
"Sets the directory used to temporarily store files that are larger than the configured size threshold."
If you want to limit the size of the uploaded file to 10KB, then use something like
if(request.getContentLengt h() > 10000){
out.println("File was too big! Use your back button " + "and a file <" + 10000 + "Bytes.");
}
According to the API the setSizeThreshold method
"Sets the size threshold beyond which files are written directly to disk."
When the threshold is exceeded then the repository is used. From API, the setRepository method
"Sets the directory used to temporarily store files that are larger than the configured size threshold."
If you want to limit the size of the uploaded file to 10KB, then use something like
if(request.getContentLengt
out.println("File was too big! Use your back button " + "and a file <" + 10000 + "Bytes.");
}
ASKER
I added if(request.getContentLengt h() > 10000)
but it threw
org.apache.commons.fileupl oad.FileUp loadBase$S izeLimitEx ceededExce ption: the request was rejected because its size (611162) exceeds the configured maximum (102400)
but it threw
org.apache.commons.fileupl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I find it easier to use
if(request.getContentLengt h() > 10400){ // added extra to include any parameters that were sent
response.sendRedirect("err or.jsp");
}
and don't use setFileSizeMax or setSizeMax just leave the defaults.
if(request.getContentLengt
response.sendRedirect("err
}
and don't use setFileSizeMax or setSizeMax just leave the defaults.