I am using spring-webflux
and want to upload files .... everything works great with just spring-web
but when it comes to webflux
i have not a clue what's wrong .
Be careful in the difference ... i am using :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
So let's say we have the below @RestController
, for Spring Web
it works like charm:
@PostMapping(value = "/uploadFile")
public Response uploadFile(@RequestParam("file") MultipartFile file) {
}
Now trying the same with Spring-webflux
produces the below error :
{
"timestamp": "2019-04-11T13:31:01.705+0000",
"path": "/upload",
"status": 400,
"error": "Bad Request",
"message": "Required MultipartFile parameter 'file' is not present"
}
I found from a random stackoverflow question that i have to use @RequestPart
instead of @RequestParam
but now i am getting the below error and i don't have a clue why this happens ?
The error is the below :
{
"timestamp": "2019-04-11T12:27:59.687+0000",
"path": "/uploadFile",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/xml' not supported for bodyType=org.springframework.web.multipart.MultipartFile"
}
Even with .txt
files is producing the same error :
{
"timestamp": "2019-04-11T12:27:59.687+0000",
"path": "/uploadFile",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/xml' not supported for bodyType=org.springframework.web.multipart.MultipartFile"
}
Below is the Postman Configuration which is pretty straight forward , i am just calling with a post request and modified only the body as shown in the picture .
By the way i have added the needed properties on application.properties too :)
## MULTIPART (MultipartProperties)
# Enable multipart uploads
spring.servlet.multipart.enabled=true
# Threshold after which files are written to disk.
spring.servlet.multipart.file-size-threshold=2KB
# Max file size.
spring.servlet.multipart.max-file-size=200MB
# Max Request Size
spring.servlet.multipart.max-request-size=215MB
spring-web
we are usingspring-webflux
and there is all the problem . I used the same request forspring-web
and it works :'( i am troubleshouting with it all day :( – Foliole.txt
file i get the below :Content type 'text/plain' not supported for bodyType=org.springframework.web.multipart.MultipartFile
– Foliolespring-webflux
– Foliole