【发布时间】:2021-03-07 07:09:39
【问题描述】:
我遇到了与此处提到的相同的问题。
Stream upload 'POST' in Spring WebClient
我需要通过 Spring WebClient 上传大文件,并且我不想读取内存中的文件来执行此操作。
我将文件存储在 Minio S3 存储桶中,界面允许我以 java.io.InputStream 的形式接收文件。
然后我想将其作为上传主体流式传输到另一个服务端点。
产生Content type 'application/octet-stream' not supported for bodyType=org.springframework.web.reactive.function.BodyInserters 错误的解决方案是通过以下方式产生的:
public String uploadFile(String fileId, String fileName) {
InputStream fileInputStream = minioClient.getObject(bucketName, fileId);
return webClient.post()
.uri(properties.getUrl())
.contentType(APPLICATION_OCTET_STREAM)
.headers(httpHeaders -> {
httpHeaders.set(FILE_NAME, fileName);
})
.bodyValue(BodyInserters.fromResource(fileInputStream)
.retrieve()
.bodyToFlux(String.class)
.blockFirst();
}
【问题讨论】:
标签: spring file-upload inputstream flux spring-webclient