aws file delete using node.js code example

Example 1: how to store and delete s3 image using node js

const s3 = new AWS.S3(
  {  accessKeyId: IAM_USER_KEY,  /* required */# Put your iam user key 
   secretAccessKey: IAM_USER_SECRET, /* required */  # Put your iam user secret key
   Bucket: BUCKET_NAME     /* required */     # Put your bucket name
  }
);

s3.deleteObject({
  Bucket: MY_BUCKET,
  Key: 'some/subfolders/nameofthefile1.extension'
},function (err,data){})

   s3.createBucket({
            Bucket: BUCKET_NAME        /* Put your bucket name */
        }, function () {
            s3.putObject(params, function (err, data) {});
        });

Example 2: nodejs aws s3 bucket delete item

var params = {  Bucket: 'your bucket', Key: 'your object' };

s3.deleteObject(params, function(err, data) {
  if (err) console.log(err, err.stack);  // error
  else     console.log();                 // deleted
});

Tags:

Go Example