SpringBoot's @MultipartConfig maxFileSize not taking effect

后端 未结 7 1526
野性不改
野性不改 2021-02-02 07:52

I have a controller with a MultipartConfig annotation (a snippet of which is show below):

@RestController
@RequestMapping(\"packages\")
@MultipartCo         


        
7条回答
  •  面向向阳花
    2021-02-02 08:28

    With Spring Boot 2.0, you should use this in your application.yml

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

    From documentation:

    Spring Boot embraces the Servlet 3 javax.servlet.http.Part API to support uploading files. By default, Spring Boot configures Spring MVC with a maximum size of 1MB per file and a maximum of 10MB of file data in a single request. You may override these values, the location to which intermediate data is stored (for example, to the /tmp directory), and the threshold past which data is flushed to disk by using the properties exposed in the MultipartProperties class. For example, if you want to specify that files be unlimited, set the spring.servlet.multipart.max-file-size property to -1.

    Extracted from Appendix A of documentation

    spring.servlet.multipart.max-file-size=1MB # Max file size. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes, respectively.

    spring.servlet.multipart.max-request-size=10MB # Max request size. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes, respectively.

提交回复
热议问题