Clement
Clement

Reputation: 4811

File upload in spring webflux - Required MultipartFile parameter 'file' is not present

I'm trying to upload a file using Spring Webflux, but I'm getting the error Required MultipartFile parameter 'file' is not present.

@RestController
@RequestMapping("/documents")
class MyController(val myService: MyService) {

    @PostMapping
    fun create(@RequestParam("file") file: MultipartFile): Mono<ResponseEntity<Map<String, String>>> {
        return myService.create()
    }
}

I've also tried replacing @RequestParam("file") file: MultipartFile with ServerRequeset, but I get the error:

"Failed to resolve argument 0 of type 'org.springframework.web.reactive.function.server.ServerRequest' on public reactor.core.publisher.Mono>> co.example.controllers.MyController.create(org.springframework.web.reactive.function.server.ServerRequest)"

Upvotes: 2

Views: 2425

Answers (1)

Clement
Clement

Reputation: 4811

Changing to FilePart from MultipartFile is what ended up working for me :)

@RestController
@RequestMapping("/v1/uploads")
class UploadsController(val exampleService: ExampleService) {

    @PostMapping(consumes = ["multipart/form-data"])
    fun create(@RequestPart("file") filePart: FilePart) = exampleService.save(filePart)

}

Upvotes: 2

Related Questions