Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Amazon's S3 return objects summaries in date order?

When I request object summaries from S3 via amazonS3Client.listObjects(), the list is returned in key alphabetical order.

Does anyone know how to get S3 to return the objects in date (lastModified) order, so the newest objects are returned first?

Thanks.

like image 758
jus_blaze Avatar asked Nov 08 '12 10:11

jus_blaze


1 Answers

Just sort the list after

Java 8

s3ObjectSummaries.sort(Comparator.comparing(S3ObjectSummary::getLastModified));

Before

Collections.sort(s3ObjectSummaries, new Comparator<S3ObjectSummary>() {
    public int compare(S3ObjectSummary o1, S3ObjectSummary o2) {
        return o1.getLastModified().compareTo(o2.getLastModified());
    }
});
like image 177
Thermech Avatar answered Sep 24 '22 22:09

Thermech