My current project involves using Angular to call an API and retrieve a byte[] of an Excel file. However, I am facing issues with the file becoming corrupted when I convert the byte[] to a file using blob. Can anyone offer assistance with this problem?
My Angular version is 9.
service.ts:
downloadFile(req?: any): any {
const options = createRequestOption(req);
return this.http.get(`${this.resourceUrl}/print`, {
params: options,
responseType:'blob' })
.toPromise();
}
component.ts:
import {saveAs} from 'file-saver';
export():void{
this.exportService.downloadFile({}) .then((blob:any)=> {
saveAs(blob, 'test.xlsx');
});
}
API response
Link to view my Excel file: