Hi there: I’m wondering if anyone knows a method for listing all files inside of an S3 bucket with node.js and Awssum, starting with the most recent file first.
By default, my code takes the first created file.
function getFileList(callback){
s3.ListObjects(coldBucket, function(err, data) {
var fileList = getFilenames(data, coldBucketPath);
callback(fileList);
});
};
Any help is much appreciated! Thanks.
this is Andy, creator of AwsSum.
That’s correct, there is no way of asking S3 for the filenames in order of inserted time. However, you can get it using the LastModified.
If you’d like to see an example to get all the keys, see this example here:
You could then store each item in an array, then sort it using LastModified. The underscore library contains a function that would be useful for this: