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

I looked through all the documents for the AWS SDK PHP and I see no way to get the object metadata. I can get the key, size, last change, etc .; but I don’t see examples in the docs of how to get metadata.

+6
source share
1 answer

The call you are 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 are only interested in the metadata of the object. To use HEAD, you must have READ access to the object.

Here is an example call from sdk version 3 (this is such an old post, I assume version 3 will be used 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

+3
source

All Articles