DEV Community

Md. Abdul Halim Rafi
Md. Abdul Halim Rafi

Posted on

How to delete file from aws s3 bucket

const s3 = new AWS.S3({
  accessKeyId: process.env.AWS_ID,
  secretAccessKey: process.env.AWS_SECRET,
});

const params = {
    Bucket: process.env.AWS_BUCKET_NAME,
    Key: `folder/subfolder/filename.fileExtension`
};

s3.deleteObject(params, (error, data) => {
  if (error) {
    res.status(500).send(error);
  }
  res.status(200).send("File has been deleted successfully");
});

Top comments (1)

Collapse
 
tezechi profile image
Tochukwu Ezechi

Hello Md. Abdul Halim Rafi
Can you show other AWS s3 object operations like update/edit object, upload object.
Thanks