-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Closed
Labels
type: documentationA documentation updateA documentation update
Milestone
Description
Here's the method to upload the file:
@RequestMapping(consumes = "multipart/form-data", method = RequestMethod.POST,
value = "/scan", produces = MediaType.APPLICATION_JSON_VALUE)
public String scan(MultipartFile file){
//code
}
Bean configuations:
@Bean
public CommonsMultipartResolver multipartResolver() {
return new CommonsMultipartResolver();
}
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize("500MB");
factory.setMaxRequestSize("500MB");
return factory.createMultipartConfig();
}
pom.xml:
<parent>
<groupId>org.springframework.boot\</groupId>
<artifactId\>spring-boot-starter-parent\</artifactId>
<version>1.1.8.RELEASE\</version>
</parent>
Request:
POST /scan HTTP/1.1
Host: localhost:9080
Cache-Control: no-cache
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="file"; filename="generate.png"
Content-Type: image/png
----WebKitFormBoundaryE19zNvXGzXaLvS5C
- When run with spring boot 1.1.8, it works fine. Method parameter is correctly bound to the value.
- When run with any other version (tried with 1.2.0, 1.2.3), method parameter is always set to null.
If I modify the method to include Request param like below:
public String scan(@RequestParam("file") MultipartFile file){
It throws an exception saying 'Required MultipartFile parameter 'file' is not present'.
I am running my spring boot app with embedded tomcat.
Metadata
Metadata
Assignees
Labels
type: documentationA documentation updateA documentation update