Spring boot 如何将异步数据写入远程端点而不获取;找不到合适的编写器异常“异常”;?

Spring boot 如何将异步数据写入远程端点而不获取;找不到合适的编写器异常“异常”;?,spring-boot,spring-webflux,Spring Boot,Spring Webflux,我有以下控制器方法: @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE, path = "/upload") public Mono<SomeResponse> saveEnhanced(@RequestPart("file") Mono<FilePart> file) { return documentService.save(file); } 我尝试了MultipartBodyBuilde

我有以下控制器方法:

@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE, path = "/upload")
public Mono<SomeResponse> saveEnhanced(@RequestPart("file") Mono<FilePart> file) {
    return documentService.save(file);
}
我尝试了MultipartBodyBuilder的所有变体(part、asyncpart、带或不带标题),但无法使其正常工作

我用错了吗?我错过了什么

问候,,
Alex

我从Spring Framework Github问题部分的一个投稿人那里得到了回复,然后找到了解决方案。 为了使这一点起作用:

asyncPart方法需要实际内容,即file.content()。我将更新它以自动展开零件内容

如果未设置两个标头,则请求将在远程端失败,表示找不到表单部件


祝有需要的人好运

您是否尝试向WebClient HTTP请求添加正确的内容类型标题?Spring在默认情况下尝试将
FilePart
序列化为JSON,但失败了。我最终发现了这个问题,它将Spring的一个贡献者的响应与另一个来源的附加信息结合起来。我把它贴出来作为回答。
public Mono<SomeResponse> save(Mono<FilePart> file) {
    MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
    bodyBuilder.asyncPart("file", file, FilePart.class);
    bodyBuilder.part("identifiers", "some static content");
    return WebClient.create("some-url").put()
            .uri("/remote-path")
            .syncBody(bodyBuilder.build())
            .retrieve()
            .bodyToMono(SomeResponse.class);

}
org.springframework.core.codec.CodecException: No suitable writer found for part: file
bodyBuilder.asyncPart("file", file.content(), DataBuffer.class)
    .headers(h -> {
        h.setContentDispositionFormData("file", file.name());
        h.setContentType(file.headers().getContentType());
    });