首页 > 解决方案 > How to perform exact match for folder name with prefix using ListObjectsV2 AWS S3 node js sdk?

问题描述

Consider the below scenario in which I have faced the problem.

Let there be documents and documentscopy folder in S3 bucket.

var params = {
    Bucket: BucketName,
    MaxKeys: 500,
    Prefix: 'documents'
}

s3.listObjectsV2(params, function (err, data) {
});

Above code provides all files in both documents and documentscopy.

What code change I have to do in order to get documents only?

标签: node.jsamazon-s3

解决方案


只需添加/到您的Prefix.

var params = {
    Bucket: BucketName,
    MaxKeys: 500,
    Prefix: 'documents/'
}

推荐阅读