javascript - 在 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
如何以正确的格式打开文件?
编辑:
- 在 Chrome 中:文件被打开但在顶部栏中没有文件名,我得到“XXXXXX”。
- 在 Firefox 中:如前所述,我在导航栏中获得带有空白页面的 blob 地址。
- 在 IE 中:它正在工作
解决方案
推荐阅读
- c# - 同时激活 Click 和 MouseDown 事件?
- python-3.x - groupby lambda 函数采用 2 列参数
- r - 如何重新排列数据框,从两个变量和第三个具有两个级别的分类变量创建四个连续变量?
- sql - 选择时间戳单元格上的最新条目
- c++ - 在STM32 Nucleo上多次触发上升沿中断
- c - 这是初始化指向结构的指针的正确方法吗?谢谢你
- reactjs - 当用户不更改默认值时,将表单中的默认值存储在状态中
- java - Spring Boot 默认使用 HTTPS,但使用 HTTP 测试配置文件
- c++ - 在 ESP8266 上的不同任务中使用类 - CPP
- java - 使用 aws-skd-java2 在分区键和排序键上查询 DynamboDB