AWS S3 : Get Last Modified Timestamp Java

Viewed 22042

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.

3 Answers

If you want to know the last modified timestamp of a specific file without listing the whole directory you can use a GetObjectRequest and then retrieve from it the ObjectMetadata. Here is an example:

S3Object fullObject = s3Client.getObject(new GetObjectRequest(bucketName, remoteFilePath));
ObjectMetadata objectMetadata = fullObject.getObjectMetadata();
Date lastModified = objectMetadata.getLastModified();
Related