I have a lambda function requesting data from s3 using AWS-SDK, it is consumend by a webapp used as file directory, but when the app request to create a new folder/directory it doesn’t shows until the user click several times on the next pages using the StartAfter value I send on the response, the bucket has around 24000 files and I need to send all the folders at the begining of the request to show’em on the view first (the front end sort the CommonPrefixes at the begining of the page as directories on the view)
I already list the objects on this way
module.exports.getDirectory = async (bucketPath = "", StartAfter = null) => {
await initS3();
const params = {
Bucket: bucketName,
Prefix: bucketPath,
Delimiter: "/",
MaxKeys: 300
};
try {
if(StartAfter) params.StartAfter = StartAfter;
console.log(JSON.stringify(params));
const data = await s3.listObjectsV2(params).promise();
return {
content: data.Contents,
Prefix: data.Prefix,
CommonPrefixes: data.CommonPrefixes,
IsTruncated: data.IsTruncated
};
} catch (err) {
console.log(err);
return {err: err};
}
}
Do I neet to sort the folder when it is created or there’s a way to get all of them when I request the objects the first time the service is consumed?
Eduardo Lemus Laguna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.