Search This Blog

2023/05/09

How to Download Images from S3 Bucket to local folder

 const fs = require('fs');

const AWS = require('aws-sdk');
const s3 = new AWS.S3({
accessKeyId: 'youraccessKeyId',
secretAccessKey: 'yoursecretAccessKey'
});

const params = {
Bucket: "yourbucketname",
Key: `profilePic/4.jpg`
};

s3.getObject(params, (err, data) => {
if (err) console.error(err);
fs.writeFileSync('./Downloads/4.jpg', data.Body);
console.log("Image Downloaded.");
});

Code is Available at https://github.com/gitsangramdesai/node-s3

No comments:

Post a Comment