spring - spring webflux 中的文件上传 - 所需的 MultipartFile 参数 'file' 不存在

标签 spring kotlin spring-webflux

我正在尝试使用 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/

相关文章:

kotlin - 按键列表分组( Kotlin )

Spring 5 WebFlux Mono 和 Flux

project-reactor - 如何在spring reactor中将两个发布者合二为一

java - Spring:用于在声明性 Spring XML 配置中实现命令式连接的习惯用法?

spring - 实体管理器尚未注入(inject):is the Spring Aspects JAR configured as an AJC/AJDT aspects library?

android - 如何在AppBarLayout Android中删除SearchView的查询文本中的下划线

Android Studio 无法解析 Mockito 类

Java Controller 需要什么代码?

java - 如果请求映射方法返回列表,Spring Boot如何解析 View 名称?

spring-boot - 创建自定义 ErrorWebExceptionHandler 失败