spring_reference/IX. ‘How-to’ guides/65.5. Handling Multipart Fi...

8 lines
992 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 65.5. 处理Multipart文件上传
Spring Boot采用Servlet 3 `javax.servlet.http.Part` API来支持文件上传。默认情况下Spring Boot配置Spring MVC在单个请求中每个文件最大1Mb最多10Mb的文件数据。你可以覆盖那些值也可以设置临时文件存储的位置比如存储到`/tmp`文件夹下及传递数据刷新到磁盘的阀值通过使用MultipartProperties类暴露的属性。如果你需要设置文件不受限制例如可以设置`multipart.maxFileSize`属性值为`-1`。
当你想要接收部分multipart编码文件数据作为Spring MVC控制器controller处理方法中被`@RequestParam`注解的MultipartFile类型的参数时multipart支持就非常有用了。
具体参考[MultipartAutoConfiguration](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java)源码。