I want to download xlsx file from the client on angular 2 using rest api.
I'm getting a byte array as a response from my GET request and I'm sending it to download function with subscribe:
let options = new RequestOptions({ search: params });
this.http.get(this.restUrl, options)
.subscribe(this.download);
download function using blob:
download(res: Response) {
let data = new Blob([res.arrayBuffer()], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;' });
FileSaver.saveAs(data, this.fileName);};
my problem is that my file is corrupted all the time. I tried a lot of versions of this but nothing works.
** also tried it with this solution and it doesn't works (the xlsx file is still corrupted) - Angular 2 downloading a file: corrupt result , the difference is that my data is an array Buffer and not string or json, and there is a difference between PDF and xlsx.
10x!