首页 > 解决方案 > 在 Firefox 中打开 blob 文件不起作用

问题描述

我会在 Firefox 上打开从服务器发送的文件。

实际上它在IE上工作。这是我如何进行的。

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);
      }
    });
}

当我打开文件时,我在新选项卡中得到一个blob:http://localhost:4200/90907276-947a-47d8-873d-40163带有空白页面的 blob 地址

我想我应该传递文件名,但不可能URL.createObjectURL

如何以正确的格式打开文件?

编辑

标签: javascripttypescriptpdffirefoxblob

解决方案


推荐阅读