AWS S3 object listing

前端 未结 6 2156
南方客
南方客 2021-02-06 20:52

I am using aws-sdk using node.js. I want to list images in specified folder e.g.\"This

6条回答
  •  遥遥无期
    2021-02-06 21:06

    You can use the Prefix in s3 API params. I am adding an example that i used in a project:

    listBucketContent: ({ Bucket, Folder }) => new Promise((resolve, reject) => {
        const params = { Bucket, Prefix: `${Folder}/` };
        s3.listObjects(params, (err, objects) => {
            if (err) {
                reject(ERROR({ message: 'Error finding the bucket content', error: err }));
            } else {
                resolve(SUCCESS_DATA(objects));
            }
        });
    })
    

    Here Bucket is the name of the bucket that contains a folder and Folder is the name of the folder that you want to list files in.

提交回复
热议问题