I'm building an application using Angular 10. I have a function that downloads files from a local server. This function works fine for extensions - .PDF, .xlsx, etc.
, except files with .msg
extension. On download, it returns a file of size 0KB.
This is my function:
downloadFile(url:string,fileName:string){
fetch(url)
.then(res => res.blob())
.then(blob => {
var a = document.createElement("a");
document.body.appendChild(a);
a.style.display = "none";
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
});
}
I tried to use these headers but still, it didn't work:
application/octet-stream
application/download
How do I resolve this problem?