Implementing large file uploads via HTTP

2019-04-12 01:00发布

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.

Exception

4条回答
可以哭但决不认输i
2楼-- · 2019-04-12 01:21

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-04-12 01:25

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.

查看更多
地球回转人心会变
4楼-- · 2019-04-12 01:25

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

查看更多
戒情不戒烟
5楼-- · 2019-04-12 01:44

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.

查看更多
登录 后发表回答