Vishal Singla
Vishal Singla

Reputation: 125

how to fetch latest time of a file in S3 in java

I am new to S3. I need to fetch a file from S3, update it, and store it back to S3, so I need to fetch the latest time of this file in an existing module; it would be good if the answer is in java.

Upvotes: 0

Views: 2202

Answers (1)

Aajan
Aajan

Reputation: 937

This gets a list of objects in the bucket. This also prints out each object’s name, the file size, and last modified date.

ObjectListing objects = conn.listObjects(bucket.getName());
do {
    for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
            System.out.println(objectSummary.getKey() + "\t" +
                    ObjectSummary.getSize() + "\t" +
                    StringUtils.fromDate(objectSummary.getLastModified()));
    }
    objects = conn.listNextBatchOfObjects(objects);
} while (objects.isTruncated());

The output will look something like this:

myphoto1.jpg 251262  2011-08-08T21:35:48.000Z
myphoto2.jpg 262518  2011-08-08T21:38:01.000Z

Ref for s3 examples including above one( LISTING A BUCKET’S CONTENT) is at: http://docs.ceph.com/docs/master/radosgw/s3/java/

Upvotes: 1

Related Questions