Hi I want to download multiple docx files in one js function. I tried using openUrl providing presigned s3 url but it only seems to manage one and the others are ignored. Then I tried passing b64 string with docx extension but that fails. Is there a recommended way?
Hi @Piotr_Kakiet,
Welcome to the Retool Community!
Are you able to share a couple of screenshots for better context?
if (!docs.length) {
throw new Error('No docs found in data');
}
const picks = docs.filter(d => d.presigned_url && d.status === 'COMPLETE');
console.log(picks.length)
const len = picks.length
for (let i = 0; i < len; i++) {
await utils.openUrl(picks[i].presigned_url)
thre are 2 files but I ever get 1 downloaded
The browser won't let you do that.
You simply can't force a user to download 2 files at once. Browsers (Chrome, Firefox, etc.) think you're spamming them or it's some kind of attack, so they block everything after that first file. That's exactly why looping openUrl will never work.
Honestly, the easiest way is to zip all those .docx files into one single .zip file and just have the user download that.
Perhaps. However, I managed to do it using below:
for (let i = 0; i < len; i++) {
console.log(picks[i].file_name)
utils.openUrl(picks[i].presigned_url,{forceReload:true})
await new Promise(r => setTimeout(r, 2000));
}
Works as a treat. Thanks me! ![]()
Clever hack, but that's unstable and will likely break on a slow internet connection. That 2-second pause won't be enough if the connection lags, and the browser will just block the rest as spam anyway.