I am having the same problem as referred to here.
Stream upload 'POST' in Spring WebClient
I need to upload large files via Spring WebClient and I don't want to read the files in memory to do that.
I have the files stored in Minio S3 bucket and the interface allows me to receive the file as java.io.InputStream.
Then I would like to stream that as an upload body to another service endpoint.
The solution, which gives an error of Content type 'application/octet-stream' not supported for bodyType=org.springframework.web.reactive.function.BodyInserters
is produced the following way:
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();
}