如何使用AWS SDK PHP从Amazon S3对象获取元数据?

Fra*_*ste 8 amazon-web-services

我一直在查看AWS SDK PHP的所有文档,但我看不到检索对象元数据的方法.我可以检索密钥,大小,上次修改等; 但我没有在文档中看到如何获取元数据的示例.

jps*_*der 6

你正在寻找的电话是headObject.根据文档:HEAD操作从对象检索元数据而不返回对象本身.如果您只对对象的元数据感兴趣,则此操作非常有用.要使用HEAD,您必须具有对该对象的READ访问权限.

这是来自版本3 sdk的示例调用(这是一个很老的帖子,我假设版本3现在将使用而不是版本2,但两个SDK都包含此调用)

$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>',
]);
Run Code Online (Sandbox Code Playgroud)

SDK文档