Get s3 metadata without getting an object

Is it possible to get only user metadata objects from S3 without having to get the whole object? I looked at the AWS SDK PHP 2 and searched google and SO without a clear answer, or maybe just not the answer I hope for.

Thanks.

+6
source share
2 answers

Maybe this will help PHP 2? It uses a Guzzle framework that I am not familiar with.

Executes the HeadObject command: the HEAD operation retrieves metadata from the 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.

Final attempt to use the Guzzle framework (unverified code):

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 Solution

 // 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']); 

Credit: http://docs.aws.amazon.com/AWSSDKforPHP/latest/#m=AmazonS3/get_object_metadata

Hope this helps!

+5
source

AWS HEAD Object 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 toArray() method. $result = $client->headObject(['Bucket' => 'YOUR-BUCKET-NAME', 'Key' => 'YOUR-FILE-NAME'])->toArray(); print_r($result['Metadata']); 
+1
source

Source: https://habr.com/ru/post/949767/


All Articles