Francis Baptiste
Francis Baptiste

Reputation: 455

How do you get metadata from Amazon S3 object using AWS SDK PHP?

I've been looking through all the docs for AWS SDK PHP and I can't see a way to retrieve an object's meta data. I can retrieve the Key, Size, Last Modified, etc; but I don't see an example in the docs for how to get the metadata.

Upvotes: 14

Views: 7957

Answers (1)

jpschroeder
jpschroeder

Reputation: 6916

The call you're looking for is headObject. According to the docs: The HEAD operation retrieves metadata from an object without returning the object itself. This operation is useful if you're only interested in an object's metadata. To use HEAD, you must have READ access to the object.

Here is the example call from the version 3 sdk (this is such an old post I assume version 3 would be used now instead of version 2, but both SDKs include this call)

$result = $client->headObject([
    'Bucket' => '<string>', // REQUIRED
    'IfMatch' => '<string>',
    'IfModifiedSince' => <integer || string || DateTime>,
    'IfNoneMatch' => '<string>',
    'IfUnmodifiedSince' => <integer || string || DateTime>,
    'Key' => '<string>', // REQUIRED
    'Range' => '<string>',
    'RequestPayer' => 'requester',
    'SSECustomerAlgorithm' => '<string>',
    'SSECustomerKey' => '<string>',
    'SSECustomerKeyMD5' => '<string>',
    'VersionId' => '<string>',
]);

SDK Documentation

Upvotes: 10

Related Questions