2

我想用 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\"

有人能帮我吗?

4

1 回答 1

0

尝试这个 ::

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

我曾经只使用这些参数来制作客户端。

于 2016-01-25T07:12:13.793 回答