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.
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){})
when you send the key dynamically, use local storage to store the key and send it dynamically to delete image
var s3 = AWS.S3(awsCredentials);
s3.deleteObject({
Bucket: MY_BUCKET,
Key: 'yourFileKey'
},function (err,data){})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With