在Spring Webflux中上传文件-不存在必需的MultipartFile参数'file'

时间:2018-10-09 11:01:27

标签: spring kotlin spring-webflux

我正在尝试使用Spring Webflux上传文件,但出现错误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()
    }
}

我也尝试用@RequestParam("file") file: MultipartFile替换ServerRequeset,但出现错误:

  

“无法在公共reactor.core.publisher.Mono上解析类型为'org.springframework.web.reactive.function.server.ServerRequest'的参数0,>>合作示例。controllers.MyController.create(org.springframework .web.reactive.function.server.ServerRequest)“

1 个答案:

答案 0 :(得分:1)

最终从FilePart转到MultipartFile才对我有用:)

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

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

}