【发布时间】:2022-11-23 23:35:08
【问题描述】:
在我开始这个问题之前,我已经围绕类似的问题(包括那些已经被问到但直到现在还没有回答的问题)浏览了多个 stackoverflow 答案。我还浏览了其中一篇中篇文章。所以,我做了相当多的研究。
我一直在尝试使用预签名的 url 下载多个文件。下面的代码几天前就可以使用(这听起来很熟悉;))但是目前,我只能下载一个文件,而且下载也是随机的。有时会下载第一个文件,有时会下载最后一个。代码如下:
downloadItem() {
let urls = [];
for(let item of this.selectedRowsData) {
//calling the service to fetch the presigned url
this.dataService.getPresignedToDownloadAll(
item.value,
item.id).subscribe((res) => {
urls.push(res);
this.download(urls);
/**if(urls.length === selectedRowData.length) {
this.download(urls);
}**/ //have tried this code too where I just invoke download only once when I have all the presigned urls
});
}
}
download(urls: any) {
var self = this;
var url = urls.pop();
setTimeout(function(){
self.snackBarService.loadComponent({
isSuccess: true,
message: MESSAGES.downloadInProgress,
});
var a = document.createElement('a');
a.setAttribute('href', url);
document.body.appendChild(a);
a.setAttribute('download', '');
a.setAttribute('target', '_self');
a.click();
// a.remove();
}, 1000)
}
任何帮助深表感谢。
【问题讨论】:
标签: javascript angular google-chrome amazon-s3