SpringBoot's @MultipartConfig maxFileSize not taking effect

后端 未结 7 1613
野性不改
野性不改 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条回答
  •  Happy的楠姐
    2021-02-02 08:41

    For setting custom limits for multipart uploads, the below properties are to be used(for a sample size of 30MB):

    spring.http.multipart.max-file-size=30MB
    spring.http.multipart.max-request-size=30MB
    

    In our company's projects, I found that one of them was on Spring Boot version 1.3.5, so for versions < 1.4 you should use

    multipart.max-file-size=30MB
    multipart.max-request-size=30MB
    

    From the docs(v1.4.0):

    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 file of 1MB per file and a maximum of 10MB of file data in a single request. You may override these values, as well as the location to which intermediate data is stored (e.g., to the /tmp directory) and the threshold past which data is flushed to disk by using the properties exposed in the MultipartProperties class. If you want to specify that files be unlimited, for example, set the spring.http.multipart.max-file-size property to -1.

    The multipart support is helpful when you want to receive multipart encoded file data as a @RequestParam-annotated parameter of type MultipartFile in a Spring MVC controller handler method.

    Same docs for version 1.3.8:

    If you want to specify that files be unlimited, for example, set the multipart.maxFileSize property to -1.

提交回复
热议问题