How to set file name for blob in typescript? For IE, I can setup file name easily but for Chrome it looks impossible. Basically I need something similar to this solution but
For chrome (and firefox) you need to do a little work around with creating an element and calling
click
:
downloadFile(data: any): void {
const blob: Blob = new Blob([data], {type: 'text/csv'});
const fileName: string = 'my-test.csv';
const objectUrl: string = URL.createObjectURL(blob);
const a: HTMLAnchorElement = document.createElement('a') as HTMLAnchorElement;
a.href = objectUrl;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(objectUrl);
}