Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in AWS by (5.6k points)

When I'm trying to rename an image in my S3 with aws-sdk-php, I'm getting this error:

AWS HTTP error: Client error: 400 AuthorizationHeaderMalformed (client): The authorization header is malformed; the Credential is mal-formed; expecting \"\/YYYYMMDD\/REGION\/SERVICE\/aws4_request\"

Here is my code file:

<?php

use Aws\S3\S3Client;

require 'aws-autoloader.php';

      $client = S3Client::factory(array(

        'credentials' => array(

        'key'    => 'mykey',

        'secret' => 'mysecret',

      ),

        'signature' => 'v4',

        'region' => 'eu-central-1',

        'version' => 'latest',

        'http'    => [

            'verify' => false

        ]

      ));

      $result = $client->copyObject(array(

            'ACL' => 'private',

            // Bucket is required

            'Bucket' => 'myfirstbucket',

            'Key' => "newfoldername/newimagename",

            'CopySource' =>  "myfirstbucket/foldername/imagename",

            'MetadataDirective' => 'REPLACE'

      ));

?>

Any solution for this?

1 Answer

0 votes
by (12.4k points)
edited by

You can try with the below code:

$client = S3Client::factory(array(

                                'key'    => $aws_key,

                                'secret' => $aws_access,

                                'region' => $aws_region

                    ));

Hope this helps! 

Looking forward to know more about AWS, then come and join aws certification training.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...