gpt4 book ai didi

tomcat - Apache Commons 文件上传 : problems uploading files greater than 100kb using HTTPS

转载 作者:行者123 更新时间:2023-11-28 23:58:13 25 4
gpt4 key购买 nike

我有一个 Java Web 应用程序,它使用 Apache Commons FileUpload 使用 servlet 上传文件。

多年来,我的基本代码在纯 http 环境 (Apache Tomcat 8.5) 上完美运行。

我已经更改了我的环境以使用 HTTPS,使用 Let's Encrypt 证书使用配置有 org.apache.coyote.http11.Http11AprProtocol 的连接器。

如果文件大于 100kb,我的上传现在会突然失败。使用纯 HTTP 环境成功上传相同的文件。

这是记录的异常:

org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. java.io.IOException: The socket [925,024,592] associated with this connection has been closed.

这是我用于管理请求的代码片段:

  DiskFileItemFactory factory = new DiskFileItemFactory();          
File repository = (File)


request.getServletContext().getAttribute("javax.servlet.context.tempdir");

factory.setRepository(repository);

ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding(encoding);

multipartItems = upload.parseRequest(request);

Tomcat 设置:

 <Connector 
port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443"
/>

<Connector
port="443" protocol="org.apache.coyote.http11.Http11AprProtocol"
maxThreads="150" SSLEnabled="true"
>
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate
certificateKeyFile="D:/prj/certificati/private.key"
certificateFile="D:/prj/certificati/certificate.crt"
certificateChainFile="D:/prj/certificati/ca_bundle.crt"
type="RSA"
/>
</SSLHostConfig>
</Connector>

我研究过这个问题,案例很少,没有解决方案。

谢谢

最佳答案

使用http2上传时间太短

尝试改变升级协议(protocol)

<UpgradeProtocol overheadWindowUpdateThreshold="-1" overheadDataThreshold="-1" writeTimeout="-1" streamWriteTimeout="-1" streamReadTimeout="-1" maxHeaderSize="8192" maxConcurrentStreams="300" readTimeout="-1" className="org.apache.coyote.http2.Http2Protocol" compressibleMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json" compression="on" compressionMinSize="1024"/>

关于tomcat - Apache Commons 文件上传 : problems uploading files greater than 100kb using HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58118776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com