Amazon s3 deleteObjects nodejs - can't make it work

I use nodejs and try to delete several objects at once. But for some reason, despite the fact that no error is returned, the operation does not work properly (files are not 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 s3.deleteObject over files and use the s3.deleteObject method, then it works very well.

I also tried to specify the bucket without its subfolders (for example, "myprivatebucket"), but again I did not get the result.

Any ideas on how to make this thing work? I am using node version: 0.10.32, and aws should be 2.0.17.

+7
amazon amazon-s3 amazon-web-services
source share
1 answer

Well, finally, I solved the problem.

When inserting files, I included the so-called subfolders in the bucket name. For example:

 { Bucket: 'myprivatebucket/some/subfolders', Key: 'nameofthefile1.extension' } 

This seems to be wrong and should be avoided. The correct use case:

 { Bucket: 'myprivatebucket', Key: 'some/subfolders/nameofthefile1.extension' } 

After inserting such elements, just use the same bucket and keys to delete objects, and it will work! At least it worked for me!

+14
source share

All Articles