- 排除
MultipartAutoConfiguration
@SpringBootApplication (exclude = {MultipartAutoConfiguration.class})
- 添加
MultipartResolver
//显示声明CommonsMultipartResolver为mutipartResolver
@Bean(name = "multipartResolver")
public MultipartResolver multipartResolver() {
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("UTF-8");
//resolveLazily属性启用是为了推迟文件解析,以在在UploadAction中捕获文件大小异常
resolver.setResolveLazily(true);
resolver.setMaxInMemorySize(40960);
//上传文件大小 5M 5*1024*1024
resolver.setMaxUploadSize(5 * 1024 * 1024);
return resolver;
}
- 添加
@RequestParam
@PostMapping("/upload")
public ApiResponse upload(@RequestParam("file") MultipartFile multipartFile) {
// other code ...
}
本文由 Clive 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为:
2019/06/25 17:03