Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

service.ts

return this.http.get(URL);             
like image 357
Joes Apzara Avatar asked Oct 21 '25 15:10

Joes Apzara


1 Answers

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`)
 });
like image 172
Adrita Sharma Avatar answered Oct 23 '25 06:10

Adrita Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!