I am using nodejs and trying to delete multiple objects at a time. But for some reason, despite not returning any error, the operation does not work as expected (the files are not being deleted). Here is the code:
s3.deleteObjects({
Bucket: 'myprivatebucket/some/subfolders',
Delete: {
Objects: [
{ Key: 'nameofthefile1.extension' },
{ Key: 'nameofthefile2.extension' },
{ Key: 'nameofthefile3.extension' }
]
}
}, function(err, data) {
if (err)
return console.log(err);
console.log('success');
});
If i try to iterate over the files, and use the s3.deleteObject
method then it works pretty good.
I also tried to specify to bucket without its subfolders (like 'myprivatebucket') but I got no result again.
Any ideas on how to make this thing work? I am using node version: 0.10.32 and the aws should be 2.0.17.
Well finally I've resolved the problem.
When inserting the files, I was including the so-called sub-folders into the bucket name. For example:
{ Bucket: 'myprivatebucket/some/subfolders', Key: 'nameofthefile1.extension' }
This is apparently wrong and should be avoided. The correct use case is as follows:
{ Bucket: 'myprivatebucket', Key: 'some/subfolders/nameofthefile1.extension' }
After inserting the items like this, just use the same bucket and keys to delete objects and it will work! At least, for me it worked!
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