【问题标题】:How to set the upload size in apache commons upload如何在apache commons上传中设置上传大小
【发布时间】:2012-03-28 07:56:11
【问题描述】:

您好,我正在使用 apache commons upload 来上传文件

   File file=this.getFile();//getter method for the file
   String fileName="test.zip";
   File target=new File("D:\\test",target);
   FileUtils.copyFile(file,target);

但是这样我最多只能上传 20MB。如何在这段代码中设置上传文件的大小。

【问题讨论】:

    标签: java apache-commons-fileupload


    【解决方案1】:

    这是在documentation 中。你所要做的就是打电话:

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);
    
    // Set overall request size constraint
    upload.setSizeMax(yourMaxRequestSize);
    
    // Parse the request
    List /* FileItem */ items = upload.parseRequest(request);
    

    以上内容来自可通过链接获得的示例代码。但是,我不知道 Apache Commons Upload 中的 FileUtils 类,我怀疑您实际上可能在谈论不同的库。在 Commons IO 中有一个名为 FileUtils 的类看起来它与您的代码示例的关系更好一些,您是否有机会谈论 Commons IO 和 复制 一个文件,而不是 上传 一个文件?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 2014-08-09
      • 1970-01-01
      • 2020-01-17
      相关资源
      最近更新 更多