aws-sdk S3:使用listObjectsV2列出所有键的最佳方法 [英] aws-sdk S3: best way to list all keys with listObjectsV2
本文介绍了aws-sdk S3:使用listObjectsV2列出所有键的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用vcode版本的 listObjects
API调用,您将可以从 SO回答中完成类似的操作.
With the v1 version of the listObjects
API call, you would have done something like from this SO answer.
var allKeys = [];
function listAllKeys(marker, cb) {
s3.listObjects({Bucket: s3bucket, Marker: marker}, function(err, data){
allKeys.push(data.Contents);
if(data.IsTruncated)
listAllKeys(data.NextMarker, cb);
else
cb();
});
}
listObjectsV2
函数的等效项是什么?
What would be the equivalent of the listObjectsV2
function?
推荐答案
这是从存储桶中获取键列表的代码.
Here is the code to get the list of keys from a bucket.
var params = {
Bucket: 'bucket-name'
};
var allKeys = [];
listAllKeys();
function listAllKeys() {
s3.listObjectsV2(params, function (err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
} else {
var contents = data.Contents;
contents.forEach(function (content) {
allKeys.push(content.Key);
});
if (data.IsTruncated) {
params.ContinuationToken = data.NextContinuationToken;
console.log("get further list...");
listAllKeys();
}
}
});
}
这篇关于aws-sdk S3:使用listObjectsV2列出所有键的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文