How to add a context menu feature to download content fetched from external

We have a Vaadin 14 application where we use to show data and in one of the context menu we let the use to Download the report of that specific record which is a zip file generated from another microservice generating the application/octet-stream. What I’m looking for is to fetch the content from external service on click of the context menu link and not prior to it.

External Service

response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.addHeader("content-disposition", String.format("attachment; filename=\"\"", id));
OutputStream servletOs = response.getOutputStream();

Rest Client

ResponseEntity<byte[]> response =, HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), byte[]
if (response.getStatusCode().equals(HttpStatus.OK)) {
	return response.getBody();

Grid View

byte[] bytes = fetchedFromExternalService();
final String filename = "something";
StreamResource resource = getStreamResource(filename, bytes);
Anchor anchor = new Anchor(resource, "Download");
anchor.getElement().setAttribute("download", true);
private StreamResource getStreamResource(String filename, byte[] content) {
	return new StreamResource(filename, () -> new ByteArrayInputStream(content));