Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 : Get Last Modified Timestamp Java

Tags:

java

amazon-s3

I have written a java code to get the list of files in a AWS S3 bucket's folder as a list of strings. Is there any direct function that I could use to get the last modified timestamp of a file that we see in the s3 buckets.

like image 455
Codex Avatar asked Mar 22 '16 11:03

Codex


1 Answers

You can get the lastModified as a java.util.Date via the S3ObjectSummary object.

// ...
ListObjectsV2Request listObjectsV2Request = new ListObjectsV2Request()
    .withBucketName("my-bucket")
    .withMaxKeys(1000);

ListObjectsV2Result result = s3client.listObjectsV2(listObjectsV2Request);

for (S3ObjectSummary objectSummary : result.getObjectSummaries()) {
    // objectSummary.getLastModified() as java.util.Date
}
like image 142
H6. Avatar answered Sep 28 '22 08:09

H6.