Retrieving a timestamp for an S3 upload

Viewed 377

I want to handle synchronizing between browser cache (indexedDB) and S3. Therefore I utilize timestamps.

The tricky part is, that my browser application needs to know the exact "last update" timestamp of the file in S3 to store it alongside the locally cached file (so I can sense differences on the one or other side by timestamps being not equal).

Currently, my best solution is:


  // Upload of file
    var upload = new AWS.S3.ManagedUpload({
        params: {
            // some params
        }
    });
    await upload.promise();
  // Call of listObjectsV2
    var s3Objects = await s3.listObjectsV2(params).promise();
    // get "LastModified" value from listObjectsV2

I really dislike this solution as it makes an extra call for "listObjectsV2", that needs time and is charged by AWS.

From the top of my head, I expected there should be something in the return params of the upload, that I can utilize. But I can't find anything. What am I missing?

1 Answers

Looking at the documentation for the AWS SDK for JavaScript, I don't think you're missing anything at all: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3/ManagedUpload.html#promise-property

It is simply not returning any date time field after a successfull upload.

(I've been searching for something like this myself, only for NET. In the end I had to start sending metadata requests after uploading.)

Perhaps listening to S3 events could be an alternative: https://aws.amazon.com/blogs/aws/s3-event-notification/

Related