Issue
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.
service.ts
return this.http.get(URL);
Solution
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`)
});