Ben*_* D. 6 google-chrome angular
我在我的 Angular 6 应用程序中使用服务从我的 REST API 下载文件(blob)。此服务适用于小于 10MB 的文件(在 Chrome 和其他浏览器上)。我目前正在尝试下载一个 14MB 的文件,但它失败了,仅在 Chrome 上(按预期与 Firefox 一起使用)
我认为这是 Chrome 的限制,但我在 SO 或 Angular 文档上找不到任何关于此的信息。
这是我的服务
displayFile(url: string) {
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
this.http.post('my_backend_path/getFile', JSON.stringify({urlData: url}), {responseType: "blob", headers})
.subscribe((data: any) => {
var urlBlob = window.URL.createObjectURL(data);
window.open(urlBlob);
},
(error) => {
//Here comes the error
});
}
Run Code Online (Sandbox Code Playgroud)
我的节点 REST API 以 200 状态正确返回文件。失败来自 Chrome 控制台,如下所示:
POST my_backend_path/getFile net::ERR_FAILED 200 (OK)
Run Code Online (Sandbox Code Playgroud)
在 chrome 的网络调试器中,我可以看到文件大小估计为 10.0MB(而文件实际上是 14MB)。这就是为什么我认为这是由于某些 Chrome 或 Angular HTTPClient 限制造成的。
有没有人有想法?
我遇到了这个问题 - Chrome 在 API 调用上记录了 net::ERR_FAILED 200 (OK),返回了超过 10mb 的 json。令人惊讶的是,它在隐身模式下工作,周围没有人受到影响。
我的解决方案是清理 C: 驱动器。它的磁盘空间很小(大约 200 Mb)。磁盘清理后,Chrome 开始正常运行。
小智 5
I think you need to change the responseType : to ArrayBuffer. It works for me
{responseType: "arrayBuffer", headers})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3227 次 |
| 最近记录: |