我试图在IE中以角度+节点设置开始下载时遇到问题。以编程方式从回调中以编程方式开始下载在IE
首先,这里是我当前的进程:
- 用户点击下载按钮
- 它要求将文件从节点服务器
- 节点服务器生成的文件,并将其发送回JS控制器
- 的JS控制器生成该文件的URL,并将其作为一个下载
版本我一直使用到现在看起来是这样的(简化清楚起见):
var self = this;
var invisibleLink = document.getElementById('invisible-link');
this.services.http.post("createPdf", {foo: 'bar}, {responseType: 'arraybuffer'})
.then(function(response){
var file = new Blob([response.data], {type: 'application/pdf'});
var fileURL = window.URL.createObjectURL(file);
invisibleLink.href = fileURL;
invisibleLink.download = 'myDownloadedFile';
invisibleLink.click();
});
这种运作良好,它的顺利,一切都在... FF和铬。在IE(11)中,我收到“错误:访问被拒绝”。
显然.download
和/或.click()
不被接受,所以下面的其他SE问题,我试图使用window.location
。不幸的是,这似乎也不起作用。
下面是我试过了,结果:
window.location.href = fileURL;
// Error: Permission denied
window.location.href = file;
// Opens "http://myurl.com/[object%20Blob]"
window.location = fileURL;
// Error: Access is denied.
window.location = file;
// Opens "http://myurl.com/[object%20Blob]"
window.open= file;
// Nothing happens
window.open= fileURL;
// Nothing happens
// For all tests, using document instead of window had the exact same results
我真的真的真的需要触发从回调的下载,考虑到:
- 1 /生成的文件,所以没有现有的URL
- 2 /文件生成可能需要1到20s之间的任何地方,所以任何使用超时的问题都会产生问题
无论如何,从IE中的回调开始下载?
你见过对付IE <10什么? – godskook