我遇到了这里提到的同样的问题。
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();
}
https://stackoverflow.com/questions/64987563
复制相似问题