Java 通过 HTTP 实现大文件上传
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19158118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Implementing large file uploads via HTTP
提问by Dmitrii Pisarenko
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).
我需要创建一个基于 Apache Tomcat 的 Web 应用程序,它可以通过 HTTP(多部分表单 POST 请求)接收大型(100 MB 或更多)文件。
I tried Apache Commons Fileupload and it works for smaller files (20-40 MB). But it doesn't work for large files.
我尝试了 Apache Commons Fileupload,它适用于较小的文件(20-40 MB)。但它不适用于大文件。
Are there any obvious ways to implement large file upload except
除了实现大文件上传,有没有什么明显的方法
- using Java applet at the client side,
- tweaking Tomcat's settings?
- 在客户端使用 Java 小程序,
- 调整Tomcat的设置?
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 (03.10.2013):这是我在上传大约 2 个文件时在服务器端得到的例外。120 总大小。
采纳答案by Dmitrii Pisarenko
回答by tbraun89
If it's a error in tomcat you could increase the maximum upload file size and the maximum request size in your web.xml
.
如果是 tomcat 中的错误,您可以增加最大上传文件大小和最大请求大小web.xml
。
An example with 50MB max upload:
最大上传 50MB 的示例:
<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.
如果您的 tomcat 前面有一个 apache 或 nginx 作为代理,您可能还需要在服务器配置中增加它们的上传/发布大小值。
回答by RAlex
Set the maxPostSize
attribute value of the HTTP connector in your Tomcat server.xml
config file:
maxPostSize
在 Tomcatserver.xml
配置文件中设置HTTP 连接器的属性值:
<Connector port="8080" ... maxPostSize="<high_file_size_value>" ...>
Tomcat reference doc: http://tomcat.apache.org/tomcat-7.0-doc/config/http.html#Attributes
Tomcat 参考文档:http: //tomcat.apache.org/tomcat-7.0-doc/config/http.html#Attributes