我正在使用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');
});
如果我尝试迭代文件,并使用s3.deleteObject
方法,那么它的效果非常好。
我还尝试指定没有子文件夹的桶(比如'myprivatebucket'),但我没有得到任何结果。
关于如何使这件事有用的任何想法?我使用的是节点版本:0.10.32,aws应该是2.0.17。
答案 0 :(得分:16)
最后我已经解决了这个问题。
插入文件时,我将所谓的子文件夹包含在存储桶名称中。例如:
{ Bucket: 'myprivatebucket/some/subfolders', Key: 'nameofthefile1.extension' }
这显然是错误的,应该避免。正确的用例如下:
{ Bucket: 'myprivatebucket', Key: 'some/subfolders/nameofthefile1.extension' }
插入这样的项目后,只需使用相同的桶和键删除对象即可使用!至少,对我而言,它有效!