I am making REST API call to get an array of pre-signed URLs from S3. These URL are files that could be XML, CSV, JSON etc.
How do I loop download files from these URLs without opening a new tab? I do not want to use AWS SDK for NodeJS to avoid tight coupling with my front-end. Application currently has Angular 7, NodeJS and ExpressJS.
getFile(url, params){
this.awsservice.getFile(url, params).subscribe(
(response) => {
const res = JSON.parse(JSON.stringify(response));
var apiList = [];
for (var key in res) {
if(key == 'api'){
apiList = res[key];
}
}
apiList.forEach(function (url) {
// Logic to download file
document.location.assign(url) //Only seems to download the last file in the array
console.log("Download started: "+url);
});
},
(error) => {
this.tempErrorFlag = true;
const errorMsg = error;
console.log(`ERROR ::: reInitiate API ::: ${errorMsg.message}`);
});
}
I tried adding document.location.assign(url)
but it only seems to download the last url in the array. Even adding delay
didn't help.
Appreciate your help.