[Fixed] How to download a file in angular, which is received as application/octet-stream


I’m creating a webpage that has to download a file in csv format.
The REST API returns the file.

I get an error while accessing the Api.
I guess that is because the file is getting converted to JSON. How can I get it from the back end and handle it.


return this.http.get(URL);             


You can use file-saver

import * as FileSaver from 'file-saver';

this.http.post(url, resource, { responseType: 'blob' })
 .subscribe((resp: any) => {
    FileSaver.saveAs(resp, `filename.csv`)

Leave a Reply

(*) Required, Your email will not be published