Reputation: 103
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.
Upvotes: 10
Views: 8054
Reputation: 4451
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());
}
});
Upvotes: 2
Reputation: 400
Interesting Problem. In my opinion the problem with ListObject is that you have to download the Objects, which can be in GB sizes.
There is no solution about this but i found a workaround in the .net development forum.
Upvotes: -1