我正在尝试将一个文件夹复制到 aws s3 中的另一个文件夹,如下所示
$s3 = S3Client::factory(
array(
'credentials' => array(
'key' => 'testbucket',
'secret' => BUCKET_SECRET //Global constant
),
'version' => BUCKET_VERSION, //Global constant
'region' => BUCKET_REGION //Global constant
)
);
$sourceBucket = 'testbucket';
$sourceKeyname = 'admin/collections/Athena'; // Object key
$targetBucket = 'testbucket';
$targetKeyname = 'admin/collections/Athena-New';
// Copy an object.
$s3->copyObject(array(
'Bucket' => $targetBucket,
'Key' => $targetKeyname,
'CopySource' => "{$sourceBucket}/{$sourceKeyname}",
));
它抛出错误为
致命错误:未捕获的异常“Aws\S3\Exception\S3Exception”,消息为“在“ https://testbucket.s3.us-east-2.amazonaws.com/admin/collections/Athena-New ”上执行“CopyObject”时出错; AWS HTTP 错误:客户端错误:PUT
https://testbucket.s3.us-east-2.amazonaws.com/admin/collections/Athena-New 导致404 Not Found响应: NoSuchKey指定的密钥不存在。admin/collections/AthenaNoSuchKey指定的密钥不存在。admin/collections/Athena29EA131A5AD9CB836OjDNLgbdLPLMd0t7MuNi4JH6AU5pKfRmhCcWigGAaTuRlq6MTXuRlq6MuNi4KfRmhCcWigGAaTuRlq6MTXi
我不明白为什么它会生成错误的存储桶 url,例如
https://testbucket.s3.us-east-2.amazonaws.com/admin/collections/Athena-New
虽然正确的 aws 存储桶 url 是
https://s3.us-east-2.amazonaws.com/testbucket/admin/collections/Athena-New
为什么它将存储桶名称附加到 url 中的 s3 之前?
简单来说,我想复制的内容
https://s3.us-east-2.amazonaws.com/testbucket/admin/collections/Athena
至
https://s3.us-east-2.amazonaws.com/testbucket/admin/collections/Athena-New
泛舟湖上清波郎朗