Implementing large file uploads via HTTP

2019-04-12 01:17发布

问题:

I need to create a web application based on Apache Tomcat, which can receive large (100 MB or more) files via HTTP (multipart form POST request).

I tried Apache Commons Fileupload and it works for smaller files (20-40 MB). But it doesn't work for large files.

Are there any obvious ways to implement large file upload except

  1. using Java applet at the client side,
  2. tweaking Tomcat's settings?

Update 1 (03.10.2013): Here's the exception that I get at the server side when uploading 2 files with approx. 120 total size.

回答1:

I found another solution. On the FileUpload's web site there is a page about the Streaming API.

The code snippet on that page solved my problem.



回答2:

If it's a error in tomcat you could increase the maximum upload file size and the maximum request size in your web.xml.

An example with 50MB max upload:

<multipart-config>
    <!-- 50MB max -->
    <max-file-size>52428800</max-file-size>
    <max-request-size>52428800</max-request-size>
    <file-size-threshold>0</file-size-threshold>
</multipart-config>


If you have an apache or nginx infront of your tomcat as proxy, you may have to increase their upload/post size values too in the server config.



回答3:

Set the maxPostSize attribute value of the HTTP connector in your Tomcat server.xml config file:

<Connector port="8080" ... maxPostSize="<high_file_size_value>" ...>

Tomcat reference doc: http://tomcat.apache.org/tomcat-7.0-doc/config/http.html#Attributes



回答4:

Refer here

It can be done using plupload. In case you dont want to use applet, you can use flash,html5 etc.. Any number of files of any size can be uploaded.