我正在尝试使用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)“
答案 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)
}