Using the flux Webclient, I'm trying to stream a org.springframework.core.io.buffer.DataBuffer file I downloaded from another webclient to a new endpoint.
This endpoint (which I do not control) requires 2 headers to be set on the upload: Content-Length and Content-Range.
If I set them manually as per the hard coded test below it all goes well. I'm unsure where to get started to have these set dynamically as the Flux databuffer gets uploaded.
public Mono<ResourceResponse>uploadFile(URI destination, Flux<DataBuffer> inputFile){
WebClient webClient = WebClient.create();
return webClient.put()
.uri(destination)
// .header(HttpHeaders.CONTENT_LENGTH, "12")
// .header(HttpHeaders.CONTENT_RANGE, "bytes 0-11/12")
.body(BodyInserters.fromDataBuffers(inputFile))
.retrieve()
.bodyToMono(ResourceResponse.class);
}
Should I be doing more on the client to extract these headers?
public Flux<DataBuffer> downloadFile(URI uri) {
return botClient.get().uri(uri)
.accept(MediaType.APPLICATION_OCTET_STREAM)
.retrieve().bodyToFlux(DataBuffer.class);
}