When using commons file upload without setting the flag:
spring.servlet.multipart.enabled=false
You will get:
DefaultHandlerExceptionResolver : Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present]
SB version 2.1.3.RELEASE Commons-fileupload:1.3.1 See: demo_commons_file_upload.zip
Comment From: wilkinsona
Thanks for the sample. You've defined your multipartResolver bean using the following @Bean method:
@Bean
public MultipartResolver multipartResolver() {
CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
commonsMultipartResolver.setMaxUploadSize(100000);
commonsMultipartResolver.setDefaultEncoding("UTF-8");
return commonsMultipartResolver;
}
As the return type is MultipartResolver rather than CommonsMultipartResolver, you're hiding the fact that it's a CommonsMultipartResolver. As a result, the MultipartConfigElement defined by MultipartAutoConfiguration is still auto-configured and you're missing out on the fix for https://github.com/spring-projects/spring-boot/issues/7735. It's defined with the following @Bean method:
@Bean
@ConditionalOnMissingBean({ MultipartConfigElement.class,
CommonsMultipartResolver.class })
public MultipartConfigElement multipartConfigElement() {
return this.multipartProperties.createMultipartConfig();
}
If you change the signature of your @Bean method to show that it returns CommonsMultipartResolver, the auto-configuration of the MultipartConfigElement will back off and uploads will work.
Comment From: sachinmegadi
You have used @RequestParam("file"). While uploading csv or text file use key as 'file'.