简体   繁体   English

aws s3 sdk 按多个前缀列出对象

[英]aws s3 sdk list objects by multiple prefixes

is there any possible way/endpoint to use sdk to list objects by multiple prefixes?是否有任何可能的方式/端点使用 sdk 按多个前缀列出对象? i have a file in a specific folder (will call it original for now) with an uuid identifier and 2 other files with the same uuid in different folders.我在特定文件夹中有一个文件(现在将其称为原始文件),其中有一个 uuid 标识符,另外两个文件在不同文件夹中有相同的 uuid。 i want to retrieve them by the path+uuid identifier.我想通过 path+uuid 标识符来检索它们。 it goes like this i retrieve 10 original files and want to match for each file the 2 different files that have the same uuid ( i have the path they are in) how can i retrieve this thing?它是这样的,我检索了 10 个原始文件,并希望为每个文件匹配 2 个具有相同 uuid 的不同文件(我有它们所在的路径)我怎样才能检索这个东西? i thought about using我考虑过使用

    return s3Connection
  .listObjectsV2({
    Bucket: destinationBucket,
    Prefix: path,
    Delimiter: '/',
    MaxKeys: maxKeys,
  })
  .promise();

but it does not support multiple prefixes但它不支持多个前缀

I have this same issue and couldn't change the key prefixes.我有同样的问题,无法更改键前缀。 It's pretty easy to do multiple calls, just create a prefixes array and then loop through them.进行多次调用非常容易,只需创建一个前缀数组,然后遍历它们。 All the rest of your code should be the same.您的代码的所有 rest 应该相同。

const prefixes = ['path1/data1/', 'path2/data2/', 'path3/data3/'];

prefixes.forEach(async (prefix) => {

    const S3Params = {
        Bucket: 'bucketName',
        Delimiter: '/',
        Prefix: prefix,
    };

    const res = await s3Client
        .send(new ListObjectsCommand(S3Params));

    const s3Items = res.Contents
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM