Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

Handle Tomcat aborting file upload in Spring Boot

Is there a way to handle case when Tomcat aborts file upload due to defined limits, in order to return decent response (for example 413 Payload Too Large)?

I'm using Spring Boot 2.4.0 with following configuration:

spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=20MB
spring.servlet.multipart.max-request-size=21MB
server.tomcat.max-swallow-size=21MB
server.tomcat.max-http-form-post-size=20MB

When trying to upload files larger than 21MB (or 26MB for some reason) using REST API, I receive java.net.SocketException: Connection reset by peer because Tomcat aborts the upload (closes the socket), due to defined maxSwallowSize. There's no exception in the logs by Spring. When running tests, I can see that RestTemplate retries couple of times, but eventually throws exception.


You can find MWE on GitHub.

question from:https://stackoverflow.com/questions/65873752/handle-tomcat-aborting-file-upload-in-spring-boot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...