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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…