简体   繁体   中英

Spring Boot - Multipart file maximum upload size exception

I'm developing a endpoint with Spring Boot 2.1.3<\/strong> (using the standard Tomcat embedded web server) to upload an image and I want to limit the size of the multipart upload. I can do this easily with the properties:

spring:
    servlet:
        multipart:
            max-file-size: 2MB
            max-request-size: 2MB

A bit late. You need set in application.properties or application.yml server.tomcat.max-swallow-size=-1 With it tomcat will not interferred in the upload request and the operation will be handle fully by spring and your exception controller will work perfectly. References

Please add this in your application.properties :

spring.servlet.multipart.max-file-size=50MB
spring.servlet.multipart.max-request-size=50MB

You can change the size as you need in the above config

Was having a similar problem. Tomcat kept complaining that the request was exceeding the configured maximum (2097152), even though I had the default settings in place in the global web.xml:

      <max-file-size>52428800</max-file-size>
      <max-request-size>52428800</max-request-size>

Finally figured out: the servlet class I am developing extends a servlet class that has the @MultipartConfig annotation, but my local class did not have the @MultipartConfig annotation. So the request was not being treated as multi-part, which was tripping this error.

The code that was throwing the error is in the super class at these lines:

//Search through the parts for an uploaded file
for (Part part : request.getParts()) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM