I'm trying to send a file to a spring-boot-starter-webflux application.
This is my controller:
@RestController
@RequestMapping("/fplan")
public class FplanController {
private final FplanService fplanService;
public FplanController(FplanService fplanService) {
this.fplanService = fplanService;
}
@PostMapping(value = "/file")
public Flux<Boolean> handleFileUpload(@RequestPart("file") MultipartFile file) throws IOException {
LOGGER.info(file.getOriginalFilename());
return fplanService.newFplan(file.getInputStream());
}
}
And this is my curl command line:
curl -v -F 'file=@fplan.txt' 'http://localhost:8082/fplan/file'
And this is the error output:
* Trying 127.0.0.1:8082...
* Connected to localhost (127.0.0.1) port 8082 (#0)
> POST /fplan/file HTTP/1.1
> Host: localhost:8082
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Length: 16985001
> Content-Type: multipart/form-data; boundary=------------------------76d46a224dfc0ceb
> Expect: 100-continue
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 415 Unsupported Media Type
< Content-Type: application/json
< Content-Length: 137
<
{"timestamp":"2022-03-07T15:30:53.056+00:00","path":"/fplan/file","status":415,"error":"Unsupported Media Type","requestId":"936a38c5-5"}
I already tried:
@PostMapping(value = "/file", consumes = MediaType.ALL_VALUE)
or
@PostMapping(value = "/file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
or
curl -v -X POST -H "Content-Type: multipart/form-data" -F 'file=@./fplandb_fv.txt;type=text/plain' "http://localhost:8082/fplan/file"
without success.
Any ideas whats missing?