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.setStatus(HttpStatus.OK.value());
response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.addHeader("content-disposition", String.format("attachment; filename=\"%s.zip\"", id));
OutputStream servletOs = response.getOutputStream();
output.writeTo(servletOs);

Rest Client

ResponseEntity<byte[]> response = restTemplate.exchange(endpointUrl, HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), byte[]
.class);
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);
contextMenu.addItem(anchor);
private StreamResource getStreamResource(String filename, byte[] content) {
	return new StreamResource(filename, () -> new ByteArrayInputStream(content));
}