亚马逊s3 deleteObjects nodejs - 无法让它工作

Sha*_*kan 8 amazon amazon-s3 amazon-web-services node.js

我正在使用nodejs并尝试一次删除多个对象.但由于某种原因,尽管没有返回任何错误,但操作无法按预期工作(文件未被删除).这是代码:

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');

});
Run Code Online (Sandbox Code Playgroud)

如果我尝试迭代文件,并使用该s3.deleteObject方法,那么它的效果非常好.

我也尝试指定没有子文件夹的桶(比如'myprivatebucket'),但我没有得到任何结果.

关于如何使这个东西工作的任何想法?我使用节点版本:0.10.32,aws应该是2.0.17.

Sha*_*kan 16

最后我终于解决了这个问题.

插入文件时,我将所谓的子文件夹包含在存储桶名称中.例如:

{ Bucket: 'myprivatebucket/some/subfolders', Key: 'nameofthefile1.extension' }
Run Code Online (Sandbox Code Playgroud)

这显然是错误的,应该避免.正确的用例如下:

{ Bucket: 'myprivatebucket', Key: 'some/subfolders/nameofthefile1.extension' }
Run Code Online (Sandbox Code Playgroud)

插入这样的项目后,只需使用相同的桶和键删除对象,它就会起作用!至少,对我来说它有效!