Open blob files in Firefox not working

爱⌒轻易说出口 提交于 2021-02-08 15:17:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!