如何在Spring Boot Gradle中上传大文件?
@Bean
public CommonsMultipartResolver commonsMultipartResolver() {
final CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
commonsMultipartResolver.setMaxUploadSize(-1);
return commonsMultipartResolver;
}
@Bean
public FilterRegistrationBean multipartFilterRegistrationBean() {
final MultipartFilter multipartFilter = new MultipartFilter();
final FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(multipartFilter);
filterRegistrationBean.addInitParameter("multipartResolverBeanName", "commonsMultipartResolver");
return filterRegistrationBean;
}
当我给出以上代码时,仅上传大文件。不上传字节和kb文件。
最佳答案
您可以在application.yml或属性中轻松配置多部分maxFileSize。
multipart:
maxFileSize: 30MB