Reputation: 3916
I'm working around file upload in GWT. My test application working fine. I want to set different file upload limit for different upload widget created by gwtupload
. (Project Home)
SingleUploader sUploader = new SingleUploader();
I set upload limit in web.xml
using below code. Is there any option to set different file size at run time?
<context-param>
<!-- max size of the upload request -->
<param-name>maxSize</param-name>
<param-value>3145728</param-value>
</context-param>
Upvotes: 1
Views: 1842
Reputation: 610
just override the below. it worked for me, maxSize is a protected variable in superclass
@Override
public void init() throws ServletException {
maxSize = 157286400;
super.init();
}
@Override
public void checkRequest(HttpServletRequest request) {
maxSize = 157286400;
super.checkRequest(request);
}
Upvotes: 0
Reputation: 2714
In the gwtupload UploadServlet.java class there's this method you can override which gets called before the request is passed on to org.apache.commons.fileupload.servlet.ServletFileUpload:
public void checkRequest(HttpServletRequest request) {
logger.debug("UPLOAD-SERVLET (" + request.getSession().getId() + ") procesing a request with size: " + getContentLength(request) + " bytes.");
if (getContentLength(request) > maxSize) {
throw new UploadSizeLimitException(maxSize, getContentLength(request));
}
}
If you need to modify the max allowed size client side via SingleUploader you could do this by passing the maxsize in a hidden form field and checking it in an overridden checkRequest method. The size configured in the web.xml would then be checked a second time but the apache library and be the absolute max size. i.e. you could restrict to a number /lower/ than that but not higher.
I eventually gave up on gwtupload because of things like this and rolled my own, it was fairly easy using the apache fileupload library and much more flexible.
Upvotes: 1