Arturo Marruffo Vegas
Arturo Marruffo Vegas

Reputation: 747

How to get the last modification date of a file using the Amazon S3 REST api? (without downloading the file)

I've been using this method https://coderwall.com/p/kmodkq but I think that it doesn't work for using the "HEAD" option (which is supposed to get the file metadata but not the file body).

Any help would be appreciated.

Upvotes: 3

Views: 2254

Answers (2)

stevec
stevec

Reputation: 52268

Make a HEAD request, like so

curl --head https://collidr-api.s3-ap-southeast-2.amazonaws.com/pfd.RDS

Upvotes: 1

Steffen Opel
Steffen Opel

Reputation: 64731

Using a HEAD request for an Amazon S3 object is fully supported and the method of choice for retrieving the information you are looking for:

The HEAD operation retrieves metadata from an object without returning the object itself. This operation is useful if you are interested only in an object's metadata. To use HEAD, you must have READ access to the object.

A HEAD request has the same options as a GET operation on an object. The response is identical to the GET response except that there is no response body. [emphasis mine]

Section Examples in the referenced documentation features a Sample Response which surfaces the desired Last-Modified HTTP header:

HTTP/1.1 200 OK
x-amz-id-2: ef8yU9AS1ed4OpIszj7UDNEHGran
x-amz-request-id: 318BC8BC143432E5
x-amz-version-id: 3HL4kqtJlcpXroDTDmjVBH40Nrjfkd
Date: Wed, 28 Oct 2009 22:32:00 GMT
Last-Modified: Sun, 1 Jan 2006 12:00:00 GMT
ETag: "fba9dede5f27731c9771645a39863328"
Content-Length: 434234
Content-Type: text/plain
Connection: close
Server: AmazonS3

Upvotes: 1

Related Questions