I am trying to GET a list of objects located under a specific folder in an S3 bucket using a query-string which takes the foldername as the parameter and list all objects which match that specific folder using Node JS aws-sdk
For example: http://localhost:3000/listobjects?foldername=xxx
Please suggest how to implement this functionality.
You can specify the prefix while calling the getObject
or listObjectsV2
in aws-sdk
var params = {
Bucket: 'STRING_VALUE', /* required */
Prefix: 'STRING_VALUE' // Can be your folder name
};
s3.listObjectsV2(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
By the way, S3 doesn't have folders. It is just a prefix. It shows you the folder structure to make it easy for you too navigate and see files.
Source: AWS SDK Javascript