Could you assist me in sending two S3 pre-signed URLs for every key found in the [user.idKey, user.selfieKey] array within my Express route?
I have confirmed that S3 is successfully obtaining the pre-signed URLs as they are logging to the console using the callback console.log(url).
I attempted to use "await" before the getSignedUrl method, but it seems like it may not work with S3...any suggestions on what I might be doing incorrectly?
Your help is much appreciated!
router.get(`/api/verification/load`, auth, async (req, res) => {
try {
const user = await User.findOne({ GETS A USER })
let urlArray = []
const keyArray = [user.idKey, user.selfieKey]
for (const key in keyArray) {
s3VerificationBucket.getSignedUrl(
"getObject",
{
Bucket: "app-verification",
Key: key,
Expires: 30,
},
(err, url) => urlArray.push(url) // urls are logged when console.log(url) is used
)
}
if (urlArray.length === 0) {
console.log("URL ARRAY EMPTY") -> RETURNS "URL ARRAY EMPTY"
}
const idUrl = urlArray[0]
const selfieUrl = urlArray[1]
res.send({ user, idUrl, selfieUrl })
} catch (err) {
res.status(500).send()
}
})