问题
I would open files sent from server on Firefox.
Actually it's working on IE. Here's how I proceed.
openFile(path, fileName) {
this.creditPoliciesService
.openFile(path)
.toPromise()
.then(data => {
var blob = new Blob([data.body], { type: "application/pdf" });
if (window.navigator && window.navigator.msSaveOrOpenBlob) { //if navigator is IE
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else { // Mozilla case
var fileURL = URL.createObjectURL(blob); //URL.createObjectURL takes only one parameter.
window.open(fileURL);
}
});
}
When I open file I get in new tab a blob adress blob:http://localhost:4200/90907276-947a-47d8-873d-40163
with an empty page
I think I should pass file name but it's not possible with URL.createObjectURL
How can I open files in right format ?
EDIT :
- in Chrome : files get opened but without a file name at the top bar, I get "XXXXXX" instead.
- in Firefox : as mentioned I get blob address at the navigation bar with an empty page.
- in IE : it's working
来源:https://stackoverflow.com/questions/50853533/open-blob-files-in-firefox-not-working