@RequestPart MultipartFile not working with spring boot 3.1.4

297 views Asked by At

I have below rest endpoint in my application with spring boot version as 3.1.4 and Java 17

@PostMapping(value = "/upload", consumes = {"*/*"}, produces = {"*/*"})
public ResponseEntity upload(@RequestPart(value = "file") MultipartFile file) {
    log.info("upload :: file : {}.", file);
    return null;
}

But when I tried invoking this endpoint from postman and with curl command getting the error as below

{
    "timestamp": "2023-10-21T01:47:26.217+00:00",
    "path": "/upload",
    "status": 400,
    "error": "Bad Request",
    "requestId": "6db7d61"
}

enter image description here

Any help much appreciated. Thanks.

1

There are 1 answers

0
Digital On

After spending a lot of time I figured out that spring webflux doesn't support MultipartFile, so to process the multipart data in a streaming fashion I need to use Flux, so the solution is

@PostMapping(value = "/upload", consumes = {"*/*"}, produces = {"*/*"})
public ResponseEntity upload(@RequestPart(value = "file") Flux<Part> file) {
    log.info("upload :: file : {}.", file);
    <-- Logic goes here -->
}