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

preface

Recently, the demander proposed that we could upload videos as well as pictures in the documents, which made me feel very happy. Since I mentioned the extension of file type upload service in the previous development, it is not possible to support video upload. However, the front-end child uploaded the video and said that the server returned the information of storage failure, and checked the system log. As expected, the service was abnormal, and carefully checked the original Springboot Default upload file size limit, thousands of thousands of calculations did not think of this, is a long memory.

The cause of the problem

By default, Tomcat in Spring boot supports a maximum of 1Mb for a single file and 10Mb for a single request.

org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field pic exceeds its maximum permitted size of 10485760 bytes.
Copy the code

To solve the problem

If you think you are young, you will find that even if the configuration is not good, where the problem appears, it is because different versions of Springboot corresponding to the configuration is different, most of the Internet is given after 2.0 version configuration, So if you are using a version of Spring Boot prior to 2.0, congratulations, the configuration will not take effect.

Spring Boot 1.3.x

Application.properties Configures the following

# Single file size
multipart.maxFileSize=10MB
# Limit the total size of all files in a single upload request
multipart.maxRequestSize=10MB
Copy the code
Spring Boot 1.4.x and 1.5.x

Application.properties Configures the following

# Single file size
spring.http.multipart.maxFileSize=10MB
# Limit the total size of all files in a single upload request
spring.http.multipart.maxRequestSize=10MB
Copy the code
Spring boot 2.0.x

Application.properties Configures the following

# Single file size
spring.servlet.multipart.maxFileSize=10MB
# Limit the total size of all files in a single upload request
spring.servlet.multipart.maxRequestSize=10MB
Copy the code

MaxRequestSize = maxRequestSize = maxRequestSize = maxRequestSize = maxRequestSize

reference

Spring boot Document

How to set the max size of upload file