2

I want to rename an image on S3 with aws-sdk-php. My code is as follows:

<?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'
      ));
?>

The error i get is:

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

can someone help me?

cari
  • 2,251
  • 2
  • 18
  • 27

1 Answers1

0

Try this ::

$client = S3Client::factory(array(
                                'key'    => $aws_key,
                                'secret' => $aws_access,
                                'region' => $aws_region
                    ));

I used to make client using these params only.

Ijas Ahamed N
  • 5,632
  • 5
  • 31
  • 53
  • thx for the (somehow late) answer. Since this project is old, i can not verify your answer anymore. But i will accept this as an answer, since it sounds logical:-) – cari Jan 25 '16 at 15:52