I'm looking to retrieve user-defined meta-data from objects in my S3 bucket, from the php sdk.
As per Editing Object Meta Data , User metadata is stored with the object and returned with it, and begin with "x-amz-meta-"
I have defined user metadata on objects through the console like "x-amz-meta-test", at both upload time, and adding it after the upload (through web console, not the upload API).
The test metadata is never returned. I always get the same system metadata. That is, I get only the following keys in @metadata:
Folder
statuscode
effectiveUri
headers
x-amz-id-2
x-amz-request-id
date
x-amz-bucket-region
content-type
transfer-encoding
server
Objects
Key
LastModified
date
timezone_type
timezone
ETag
Size
StorageClass
However, to achieve this in other languages, a simple method call is involved.
Get User Metadata in Android SDK
How do I go about accomplishing the same task in the PHP SDK?
Any help would be greatly appreciated :)
I had the same issue with v3 AWS SDK for PHP. After some research and testing, I determined I could use headObject
:
<?php
$headers = $s3->headObject(array(
"Bucket" => $bucket,
"Key" => $key
));
print_r($headers->toArray());
?>
Example output with System-Defined Metadata and other identifying information REMOVED:
Array
(
/* REMOVED */
[Metadata] => Array
(
[orderdate] => Mon, 31 Aug 2015 19:03:52 +0000
[color] => green
[fruit] => apple
[price] => 99.95
)
/* REMOVED */
[@metadata] => Array
(
[statusCode] => 200
[effectiveUri] => https://s3.amazonaws.com/REMOVED/REMOVED
[headers] => Array
(
[x-amz-id-2] => REMOVED
[x-amz-request-id] => REMOVED
[date] => Wed, 02 Sep 2015 04:43:02 GMT
[x-amz-meta-orderdate] => Mon, 31 Aug 2015 19:03:52 +0000
[x-amz-meta-color] => green
[x-amz-meta-fruit] => apple
[x-amz-meta-price] => 99.95
[last-modified] => Wed, 02 Sep 2015 04:11:13 GMT
[etag] => "REMOVED"
[x-amz-storage-class] => REDUCED_REDUNDANCY
[accept-ranges] => bytes
[content-type] => application/octet-stream
[content-length] => 80771
[server] => AmazonS3
)
)
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.