Increase HTTP Post maxPostSize in Spring Boot

后端 未结 14 2107
无人共我
无人共我 2020-11-28 06:48

I\'ve got a fairly simple Spring Boot web application, I have a single HTML page with a form with enctype=\"multipart/form-data\". I\'m getting this error:

相关标签:
14条回答
  • 2020-11-28 07:21

    The error here is not caused by max-file-size or max-request-size (as pointed out) but rather the container-specific max-http-post-size property. For tomcat (the default container), you can set:

    server.tomcat.max-http-post-size: 10MB
    

    Jetty:

    server.jetty.max-http-post-size: 10MB
    

    Undertow:

    server.undertow.max-http-post-size: 10MB
    

    This has the same effect as OP's answer here, but via application.properties which is much more preferable.

    0 讨论(0)
  • 2020-11-28 07:21

    This worked for me with Tomcat 8

    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName objectName = new ObjectName("Catalina:type=Connector,port=" + 8080);
    mbeanServer.setAttribute(objectName, new Attribute("maxPostSize", 100000000));
    
    0 讨论(0)
  • 2020-11-28 07:24

    I do faced kind a similar issue. where I was getting -

     "IllegalStateException multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector"
    

    Solution I have applied following property, where using max-http-form-post-size property did make the difference for me -

    server:
      tomcat:
        max-http-form-post-size: 100000000
        max-swallow-size: 100000000
    

    Along with -

    spring:
      servlet:
        multipart:
          maxFileSize: 10MB
          maxRequestSize: 10MB
    

    And it worked for me.

    0 讨论(0)
  • 2020-11-28 07:25

    There is some difference when we define the properties in the application.yaml and application.properties.

    In application.yml:

    spring:
      http:
        multipart:
          max-file-size: 256KB
          max-request-size: 256KB
    

    And in application.propeties:

    spring.http.multipart.max-file-size=128KB
    spring.http.multipart.max-request-size=128KB
    

    Note: Spring version 4.3 and Spring boot 1.4

    0 讨论(0)
  • 2020-11-28 07:26

    Apply settings for Tomcat as well as servlet

    You can set the max post size for Tomcat in application.properties which is set with an int as below. Just setting spring.servlet.multipart.max-request-size=10MB, as in some other answers, may not be enough.

    # Web properties
    spring.servlet.multipart.max-file-size=10MB
    spring.servlet.multipart.max-request-size=10MB
    
    # Server properties
    server.tomcat.max-http-post-size=100000000
    server.tomcat.max-swallow-size=100000000
    

    Working with Spring Boot 2.0.5.RELEASE

    0 讨论(0)
  • 2020-11-28 07:28

    None of the solutions did work for me and most of them are just downright offtopic because OP is talking about maxPostSize, and not maxFileSize (latter gives you a different error anyway if the size is exceeded)

    Solution: in /tomcat/conf/server.xml add maxPostSize="" attribute to Connector

    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               maxPostSize="10485760"
               redirectPort="8443" />
    
    0 讨论(0)
提交回复
热议问题