Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mbrown3321/c2c5fbff8beb991b55072aecbcdc40d5 to your computer and use it in GitHub Desktop.
Save mbrown3321/c2c5fbff8beb991b55072aecbcdc40d5 to your computer and use it in GitHub Desktop.
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