Vladimir Gabrielyan Vladimir Gabrielyan - 5 months ago 58
Node.js Question

Delete image from Amazon S3 Storage

I am trying to delete an image from Amazon S3 Storage, but it doesn't delete.

I am using following code:

var s3 = AWS.S3(awsCredentials);
s3.deleteObject({
Bucket: MY_BUCKET,
Key: myKey
},function (err,data){})


but images that I want to delete still persist.

I even used
s3.deleteObjects
function,it returns deleted object names, but when I checked the storage, the images were still there.

Answer

You have to use the key in this way and not just the name of the file that is to be deleted then it will work.

var s3 = AWS.S3(awsCredentials);
s3.deleteObject({
  Bucket: MY_BUCKET,
  Key: 'some/subfolders/nameofthefile1.extension'
},function (err,data){})