Search code examples
amazon-web-servicesamazon-s3amazon-cloudfront

Unable to get ETag value from the response


Code:

$response = $s3->copyObject(array(
     'Bucket' => $bucket,
     'Key' => $key,      
)); 

Response:

Aws\Result Object
(
    [data:Aws\Result:private] => Array
        (
            [CopyObjectResult] => Array
                (
                    [ETag] => "s906113sa3401932f56f79ec75a1c877"
                    [LastModified] => Aws\Api\DateTimeResult Object
                        (
                            [date] => 2021-05-31 04:51:54.000000
                            [timezone_type] => 2
                            [timezone] => Z
                        )

                )

            [Expiration] => 
            [CopySourceVersionId] => 
            [VersionId] => 
            [ServerSideEncryption] => 
            [SSECustomerAlgorithm] => 
            [SSECustomerKeyMD5] => 
            [SSEKMSKeyId] => 
            [SSEKMSEncryptionContext] => 
            [BucketKeyEnabled] => 
            [RequestCharged] => 
            [@metadata] => Array
                (
                    [statusCode] => 200
                    [effectiveUri] => https://bucket-dev.s3.amazonaws.com/store111/RawVideo/videogallery/file_example_MP4_480_1_5MG_1622436712.mp4
                    [headers] => Array
                        (
                            [x-amz-id-2] => DFzipf5adLLXV1435xCQO5d+R0LgDDl74o143UicbYF5biXv78G/j4HEDhoS8FsBY9C8HC+mOw8=
                            [x-amz-request-id] => 4SVDA143BSDZ49A6QJK
                            [date] => Mon, 31 May 2021 04:51:54 GMT
                            [content-type] => application/xml
                            [content-length] => 234
                            [server] => AmazonS3
                        )

                    [transferStats] => Array
                        (
                            [http] => Array
                                (
                                    [0] => Array
                                        (
                                        )

                                )

                        )

                )

            [ObjectURL] => https://bucket-dev.s3.amazonaws.com/store111/RawVideo/videogallery/file_example_MP4_480_1_5MG_1622436712.mp4
        )

    [monitoringEvents:Aws\Result:private] => Array
        (
        )

)

   

The above out I want to get the ETag value in the below code

$etag = $response->get('ETag');

I am getting the $etag value as empty. Please help and let me know how I will get it?

Note: It was working fine for aws v2 when we migrate it from aws v2 to v3 we are getting different types of responses.


Solution

  • After checking finally I just call the below:

    $etag = $response['CopyObjectResult']['ETag'];
    

    It's working fine as expected.