Created
June 6, 2021 02:52
-
-
Save mbrown3321/c2c5fbff8beb991b55072aecbcdc40d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSignedUrl(key) { | |
return new Promise((resolve, reject) => { | |
S3.getSignedUrl( | |
"getObject", | |
{ | |
Bucket: "image-upload-example-app", | |
Key: key, | |
}, | |
function (err, url) { | |
if (err) reject(err); | |
resolve(url); | |
} | |
); | |
}); | |
} | |
app.get("/files", async (req, res) => { | |
let uploads = await models.upload.findAll({ | |
where: { | |
user_id: req.user.id, | |
}, | |
}); | |
uploads = await Promise.all( | |
uploads.map(async (upload) => { | |
const url = await getSignedUrl(upload.id); | |
return { | |
...upload.toJSON(), | |
url, | |
}; | |
}) | |
); | |
res.render("files", { uploads }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment