0

We're in the process of switching to JavaConfig and we're having a problem getting multipart uploading to work

org.springframework.web.multipart.MultipartException: The current request is not a multipart request

Our configuration still uses security.xml and I tried following some suggestions

MultipartResolver and AbstractAnnotationConfigDispatcherServletInitializer

How to nicely handle file upload MaxUploadSizeExceededException with Spring Security

However, it isn't working.

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"nl.project.controller"},includeFilters={
@ComponentScan.Filter(type=FilterType.ANNOTATION,value=Controller.class),
@ComponentScan.Filter(type=FilterType.ANNOTATION,value=RestController.class)
})
public class ServletConfig extends WebMvcConfigurerAdapter{

@Bean
public CommonsMultipartResolver filterMultipartResolver(){
    CommonsMultipartResolver resolver = new CommonsMultipartResolver();
    resolver.setMaxUploadSize(5000000);
    resolver.setMaxInMemorySize(10000);
    resolver.setDefaultEncoding("utf-8");
    return resolver;
}

Any suggestions would be much appreciated!

Community
  • 1
  • 1
Marc
  • 6,773
  • 10
  • 44
  • 68

1 Answers1

0

It would be easier to answer if you posted the Security configuration and the complete stacktrace.

However, I'm guessing you are running into issues with CSRF protection. You will need to read the CSRF - Multipart (file upload) part of the reference.

If that does not help, please post your complete stacktrace and security configuration.

Rob Winch
  • 21,440
  • 2
  • 59
  • 76
  • CSRF is not enabled. There is no stacktrace. I'm using spring security 3.2.9. It just doesn't seem to be "picking up" the WebApplicationInitializer. I have a feeling it has to do with the use of Sysdeo – Marc Dec 10 '15 at 17:42
  • This seems like it would be a stacktrace: "org.springframework.web.multipart.MultipartException: The current request is not a multipart request" – Rob Winch Dec 10 '15 at 21:18
  • Darn it. I'm on the wrong question. This one I already resolved. It was a rabbit hole style problem. After moving to JavaConfig, I didn't realize some of my "@Value" references weren't being resolved. And I started changing other things, such as enabling Tomcat7 Multipart etc, all of which lead to failures even after fixing the "@Value" issue. – Marc Dec 11 '15 at 10:11