问题
I am uploading streams of (raw bytes) data using HTTP posts using WebClient:
final byte[] rawData = IOUtils.toByteArray(sourceInputStream);
webClient.post()
.uri(uri)
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.bodyValue(rawData)
.exchange()...
I am concerned there is a potentially a lot of memory used given sometimes these objects can be quite big (~200Mb) so would like to read directly from the InputStream and upload as a stream.
I tried:
bodyValue(BodyInserters.fromResource(new InputStreamResource(inputStream)))
but got exception Content type 'application/octet-stream' not supported for bodyType=org.springframework.web.reactive.function.BodyInserters
So I then tried removing the header but the data is then corrupted.
Is there a way to stream the data without passing through the in memory 'buffer' rawData[]?
Thanks
来源:https://stackoverflow.com/questions/61506325/stream-upload-post-in-spring-webclient