Using apache http client, during file download I could use
response.getFirstHeader("Content-Disposition").getValue();
Now I am switching to webflux to download file like below:
final Flux<DataBuffer> dataBufferFlux = client.get()
.accept(MediaType.APPLICATION_OCTET_STREAM)
.retrieve()
.bodyToFlux(DataBuffer.class);
final Path path = FileSystems.getDefault().getPath("/file/path/name.pdf");
DataBufferUtils
.write(dataBufferFlux, path, StandardOpenOption.CREATE)
.block();
Question: How do I get the content/header related options in webflux?
Update
I can very well do:
ClientResponse response = client.get().uri(uri)
.accept(MediaType.APPLICATION_OCTET_STREAM)
.headers(headers -> headers.setBasicAuth("admin", "admin"))
.exchange()
.block();
And it gives me what I want - System.out.println("File response asHttpHeaders :: "+response.headers().asHttpHeaders().getContentDisposition());
Output:
File response asHttpHeaders :: attachment; filename*=UTF-8''TestPdf.pdf
But I don't want to make it look ugly. I was wondering if I could get this info in my original code (using dataBufferFlux) above.
The Application:
I have an application where I need to download files in bulk (millions of files a week) in a staging area using rest API from another application, which is not fully reactive. So the whole idea is to intercept the header information in my first code (dataBufferFlux) so that I can set the filename and content type on the fly.
Simple (Re-framed) Question:
Is there a way I can retrieve the header information to get the filename and content type for the files while writing them on Staging Area (a NAS Drive).