Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get array of key from amazon s3 object

I am using amazon s3 v3 php sdk and i am trying to get key of all object for that i am using

s3->listObjects([ 'Bucket' => $somebucketName]);

this function is working fine and i am getting all object under $somebucketName bucket and its in below form

Aws\Result Object
(
    [data:Aws\Result:private] => Array
        (
            [IsTruncated] => 
            [Marker] => 
            [Contents] => Array
                (
                    [0] => Array
                        (
                            [Key] => 1.PNG
                            [LastModified] => Aws\Api\DateTimeResult Object
                                (
                                    [date] => 2015-07-14 07:22:25.000000
                                    [timezone_type] => 2
                                    [timezone] => Z
                                )

                            [ETag] => "23f423234v23v42424d23"
                            [Size] => 19980
                            [StorageClass] => STANDARD
                            [Owner] => Array
                                (
                                    [DisplayName] => sfsfssfsdf
                                    [ID] => 242f2342242342252g42f42vt34
                                )

                        )

                    [1] => Array
                        (
                            [Key] => 58.jpg
                            [LastModified] => Aws\Api\DateTimeResult Object
                                (
                                    [date] => 2015-07-14 07:20:26.000000
                                    [timezone_type] => 2
                                    [timezone] => Z
                                )

                            [ETag] => "vrtet4v4t54tvt4gvtgv45"
                            [Size] => 1226694
                            [StorageClass] => STANDARD
                            [Owner] => Array
                                (
                                    [DisplayName] => sfsfssfsdf
                                    [ID] => 34t3t3t3y43y4yg5yy4vg6u676
                                )

                        )

                    [2] => Array
                        (
                            [Key] => HDFHDFHDFHDFHFHFH
                            [LastModified] => Aws\Api\DateTimeResult Object
                                (
                                    [date] => 2015-07-30 12:07:42.000000
                                    [timezone_type] => 2
                                    [timezone] => Z
                                )

                            [ETag] => "3453345343rcf3f3r3r3f"

                )

            [Name] => SFSSD
            [Prefix] => 
            [MaxKeys] => 1000
            [@metadata] => Array
                (
                    [statusCode] => 200
                    [effectiveUri] => https://s3-us-west-2.amazonaws.com/SFSSD
                    [headers] => Array
                        (
                            [x-amz-id-2] =>  sdfsfs234sfs
                            [x-amz-request-id] => HSJFSD899
                            [date] => Mon, 03 Aug 2015 06:46:48 GMT
                            [x-amz-bucket-region] => us-west-2
                            [content-type] => application/xml
                            [transfer-encoding] => chunked
                            [server] => AmazonS3
                        )

                )

        )

)

now my question is that how to get array of key like below from above object

array("1.png","58.jpg","HDDHDFHDHDGH);
like image 651
Richerd fuld Avatar asked Aug 03 '15 06:08

Richerd fuld


People also ask

How do I find my S3 product key?

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 bucket that you want to enable an S3 Bucket Key for. Choose Properties. In the Default encryption section, under Bucket Key, you see the S3 Bucket Key setting for your bucket.

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.

What is AWS S3 object key?

The object key (or key name) uniquely identifies the object in an Amazon S3 bucket. Object metadata is a set of name-value pairs. For more information about object metadata, see Working with object metadata. When you create an object, you specify the key name, which uniquely identifies the object in the bucket.


1 Answers

Aws\Result implements ArrayAccess. You can access the contents like so:

$result = $s3->listObjects(['Bucket' => $somebucketName])
$contents = $result['Contents'];
like image 103
giaour Avatar answered Sep 20 '22 04:09

giaour