简体   繁体   English

gwtupload:设置动态文件上传大小

[英]gwtupload: Set dynamic file upload size

I'm working around file upload in GWT. 我正在解决GWT中的文件上传问题。 My test application working fine. 我的测试应用程序运行正常。 I want to set different file upload limit for different upload widget created by gwtupload . 我想为gwtupload创建的不同上传小部件设置不同的文件上传限制。 ( Project Home ) 项目首页

SingleUploader sUploader = new SingleUploader();

I set upload limit in web.xml using below code. 我使用以下代码在web.xml设置了上传限制。 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>

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: 在gwtupload UploadServlet.java类中,您可以重写此方法,该方法将在请求传递给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. 如果您需要通过SingleUploader修改客户端的最大允许大小,则可以通过在隐藏表单字段中传递maxsize并在覆盖的checkRequest方法中进行检查来实现。 The size configured in the web.xml would then be checked a second time but the apache library and be the absolute max size. 然后将再次检查在web.xml中配置的大小,但是将检查apache库并将其作为绝对最大大小。 ie you could restrict to a number /lower/ than that but not higher. 即您可以限制为一个数字/ lower /,但不能更高。

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. 我最终因为这样的事情而放弃了gwtupload,并且自己滚动了起来,使用apache fileupload库非常容易,而且更加灵活。

just override the below. 只需覆盖以下内容即可。 it worked for me, maxSize is a protected variable in superclass 它对我有用,maxSize是超类中的一个受保护的变量

@Override
public void init() throws ServletException {
    maxSize = 157286400;
    super.init();
}

@Override
public void checkRequest(HttpServletRequest request) {
    maxSize = 157286400;
    super.checkRequest(request);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM