Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 661
Francis Baptiste Avatar asked Feb 24 '14 21:02

Francis Baptiste


People also ask

How do I extract data from AWS S3?

In the Amazon S3 console, choose your S3 bucket, choose the file that you want to open or download, choose Actions, and then choose Open or Download. If you are downloading an object, specify where you want to save it. The procedure for saving the object depends on the browser and operating system that you are using.

Can Athena query metadata S3?

This solution maintains an index in an Apache Parquet file, which optimizes Athena queries to search Amazon S3 metadata. Using this approach makes it straightforward to run queries as needed without the need to ingest data or manage any servers.

What is held as metadata in an S3 object?

You can set object metadata in Amazon S3 at the time you upload the object. Object metadata is a set of name-value pairs. After you upload the object, you cannot modify object metadata.

How do I find my S3 bucket details?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to view the properties for. Choose Properties. On the Properties page, you can configure the following properties for the bucket.


1 Answers

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

like image 137
jpschroeder Avatar answered Sep 23 '22 18:09

jpschroeder