是否可以从S3获取对象自定义元数据而无需获取整个对象?我查看了AWS SDK PHP 2并搜索了google和SO,没有明确的答案,或者可能只是我希望的答案。
感谢。
答案 0 :(得分:6)
也许this会对PHP 2有所帮助?它使用了我不熟悉的Guzzle框架。
执行HeadObject命令:HEAD操作从对象检索元数据而不返回对象本身。如果您只对对象的元数据感兴趣,则此操作非常有用。要使用HEAD,您必须具有对该对象的READ访问权限。
使用Guzzle框架(未经测试的代码)的最终尝试:
use Guzzle\Service\Resource\Model
use Aws\Common\Enum\Region;
use Aws\S3\S3Client;
$client = S3Client::factory(array(
"key" => "YOUR ACCESS KEY ID",
"secret" => "YOUR SECRET ACCESS KEY",
"region" => Region::US_EAST_1,
"scheme" => "http",
));
// HEAD object
$headers = $client->headObject(array(
"Bucket" => "your-bucket",
"Key" => "your-key"
));
print_r($headers->toArray());
PHP 1.6.2解决方案
// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);
$response = $s3->get_object_metadata($bucket, 'üpløåd/î\'vé nøw béén üpløådéd.txt');
// Success?
var_dump($response['ContentType']);
var_dump($response['Headers']['content-language']);
var_dump($response['Headers']['x-amz-meta-ice-ice-baby']);
感谢:http://docs.aws.amazon.com/AWSSDKforPHP/latest/#m=AmazonS3/get_object_metadata
希望有所帮助!
答案 1 :(得分:1)
AWS HEAD对象http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectHEAD.html
use Aws\S3\S3Client;
use Guzzle\Common\Collection;
$client = S3Client::factory(array(
'key' => 'YOUR-AWS-KEY',
'secret' => 'YOUR-SECRET-KEY'
));
// Use Guzzle's toArray() method.
$result = $client->headObject(['Bucket' => 'YOUR-BUCKET-NAME', 'Key' => 'YOUR-FILE-NAME'])->toArray();
print_r($result['Metadata']);