Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

amazon s3 deleteObjects nodejs - can't get it working

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.

like image 915
Shaokan Avatar asked Sep 21 '14 21:09

Shaokan


Video Answer


1 Answers

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!

like image 190
Shaokan Avatar answered Oct 01 '22 16:10

Shaokan