Springboot Files Upload Limit Error: The field file exceeds its maximum permitted size of 1048576 bytes

An error is reported in file upload, and the interface breakpoint does not go because of the default limit of Tomcat

Spring Boot:The field file exceeds its maximum permitted size of 1048576 bytes.

The configuration file can be changed. I use YML configuration

spring:
  servlet:
    multipart:
      max-file-size: 50MB
      max-request-size: 100MB

Please like it and form good habits!

Please leave a message for questions, communication and encouragement!

The online method is not easy to use, as follows

Solution 1: Prompt for expired methods!!!

Add the following code to the startup class.

@Bean
public MultipartConfigElement multipartConfigElement() {
  MultipartConfigFactory factory = new MultipartConfigFactory();
  // single file maximum
  factory.setMaxFileSize("10240KB"); // KB,MB
  // Set the total upload data size
  factory.setMaxRequestSize("102400KB");
  return factory.createMultipartConfig();

}

Solution 2: red line burst, prompt too long

Depending on the version of spring boot, add different configurations to the application file

Spring Boot 1.3 or earlier, the configuration:

  multipart.maxFileSize = 100Mb

multipart.maxRequestSize=150Mb

Spring Boot 1.4 or later, the configuration:

  spring.http.multipart.maxFileSize = 100Mb
  spring.http.multipart.maxRequestSize = 150Mb


Spring Boot 2.0 or later: Mb change to MB

spring.servlet.multipart.max-file-size = 100MB
spring.servlet.multipart.max-request-size = 150MB

Read More: