This works for me. Just change from Flux to Mono. Seem there is no converter for Flux<byte[]>
@GetMapping(value = "/attachment/{fileId}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public Mono<byte[]> get(@PathVariable String fileId) {
return this.webClient.get()
.uri(builder ->
builder.scheme("https")
.host("external-service.com")
.path("/{fileId}")
.build(fileId)
).attributes(clientRegistrationId("credentials"))
.accept(MediaType.APPLICATION_OCTET_STREAM)
.retrieve()
.bodyToMono(byte[].class);
}
Answer from Chayne P. S. on Stack OverflowDownload and process large data efficiently with WebClient?
Spring WebClient download and upload file - Stack Overflow
Unable get fileName from Resource when using WebClient. Content-Disposition header is ignored.
kotlin - Downloading large file with spring webClient - Stack Overflow
Very similar to
Spring WebClient: How to stream large byte[] to file? https://stackoverflow.com/questions/56210186/spring-webclient-how-to-stream-large-byte-to-file/60725206#60725206
I'm fetching CSV data from a remote Rest endpoint, check for patterns within the data (against a list of user e-mail).
Basically I'm asking how to run the incoming data I'm fetching through some filter / CSV parser without ever storing data on disk or keeping the entire data in memory.
(In case of a match the matching CSV row is passed to another service class within my application.)
PS:
I found a semi working(*) solution here https://www.baeldung.com/spring-reactive-read-flux-into-inputstream
but what I dislike about this solution is having to spawn another Thread and the Thread.sleep. Or am I over thinking? (*) the code doesn't really work as it fills up the buffer until... DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144
Hello everyone, I'm currently experimenting with the Spring webclient. I already successfully uploaded a file to another api with it, but I'm currently struggling to correctly download it.
Does anyone know a good resource(or can explain it themselves) that explains how I properly download a file with WebClient from another AP.