To download a file to disk from an AWS S3 bucket with Node, we call the getObject
method.
For instance, we write
const s3 = new AWS.S3();
const s3Params = {
Bucket: "your bucket",
Key: "path/to/the/file.ext",
};
s3.getObject(s3Params, (err, res) => {
if (err === null) {
res.attachment("file.ext");
res.send(data.Body);
} else {
res.status(500).send(err);
}
});
to call the getObject
method with the Bucket
and Key
of the item to get.
We get the data from the data.Body
property.