如何用aws-sdk-php连接到amazon aws s3?

时间:2015-09-28 11:31:59

标签: amazon-s3 aws-php-sdk

我想用aws-sdk-php重命名S3上的图像。 我的代码如下:

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

我得到的错误是:

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

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

试试这个::

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

我以前只使客户使用这些参数。