我正在尝试使用 Spring Webflux 上传文件,但收到错误所需的 MultipartFile 参数"file"不存在
。
@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
,但出现错误:
"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)"
最佳答案
从 MultipartFile
更改为 FilePart
最终对我有用:)
@RestController
@RequestMapping("/v1/uploads")
class UploadsController(val exampleService: ExampleService) {
@PostMapping(consumes = ["multipart/form-data"])
fun create(@RequestPart("file") filePart: FilePart) = exampleService.save(filePart)
}
关于spring - spring webflux 中的文件上传 - 所需的 MultipartFile 参数 'file' 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52719467/