简体   繁体   中英

aws s3 sdk list objects by multiple prefixes

is there any possible way/endpoint to use sdk to list objects by multiple prefixes? 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. i want to retrieve them by the path+uuid identifier. 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? 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.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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