The browser will not display the usual interaction for downloading (display the "Save As ..." dialog, etc.) only if you go to this resource. Itโs easier to show the difference with an example:
In 1. the browser will load the page and display its contents. In 2. the browser will download the raw data and return it to you, but you must display it yourself.
You should do something similar with files. You have raw data, but you must โdisplayโ it yourself. To do this, you need to create an object URL for the downloaded file and go to it:
this.httpClient .fetch(url, {method, body, headers}) .then(response => response.blob()) .then(blob => URL.createObjectURL(blob)) .then(url => { window.open(url, '_blank'); URL.revokeObjectURL(url); });
Executes the response, reads it as a blob, creates an url object, opens it (in a new tab), and then cancels the URL.
More about object URLs: https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL
source share