Sorry if there is another post talking about this, but I can't find it and it's driving me crazy.
I made a webservice that returns a file in form of a byte array, and it works fine. After that,
On the other side, I'm developing an Angular 4 site that calls de webservice mentioned and try to download the obtained file. So I came up with the following code:
downloadFile() {
let theFile;
this.http.get(FILE_DOWNLOAD_ENDPOINT, { responseType: 'blob' })
.subscribe(data => {
theFile = new Blob([data], { type: 'application/octet-stream' });
let url = window.URL.createObjectURL(theFile);
console.log(url);
const link = document.createElement('a');
link.href = url;
link.download = 'file.pdf';
console.log(link);
link.click();
},
error => {
console.log(error);
},
() => console.log('File download completed.'));
}
This code works as expected using Chrome, but Internet Explorer doesn't download the file to the browser.
Thanks to console.log()
I can see that the link element created is different:
- blob:http://localhost:4200/55def972-dd2b-47dc-ada9-bc5514a41756 (chrome)
- blob:4F55D3BD-664D-429D-9EE6-D5D906F9CBAD (IE11)
Could anybody help me? Thanks a lot in advance!!