在 AWS 上执行“PutObject”时出错,上传失败
2022-08-30 21:32:32
我已经建立了一个 AWS 帐户,并且正在尝试在 S3 中执行我的第一个编程 PUT。我使用控制台创建了一个存储桶并将内容放在那里。我还创建了一个子目录(myFolder)并将其公开。我创建了我的 .aws/凭证文件,并尝试使用示例代码,但我收到以下错误:
在“https://s3.amazonaws.com/gps-photo.org/mykey.txt”上执行“PutObject”时出错;AWS HTTP 错误: 客户端错误: 导致响应: 访问被拒绝FC49CD (截断...)AccessDenied (client): Access Denied - Access DeniedFC49CD15567FB9CD1GTYxjzzzhcL+YySuYRx4UgV9wzTCQJX6N4jMWwA39PFaDkK2B9R+FZf8GVM6VvMXfLyI/4abo=
PUT https://s3.amazonaws.com/gps-photo.org/mykey.txt
403 Forbidden
AccessDenied
AccessDenied
我的代码是
<?php
// Include the AWS SDK using the Composer autoloader.
require '/home/berman/vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$bucket = 'gps-photo.org';
$keyname = 'my-object-key';
// Instantiate the client.
$s3 = S3Client::factory(array(
'profile' => 'default',
'region' => 'us-east-1',
'version' => '2006-03-01'
));
try {
// Upload data.
$result = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => "myFolder/$keyname",
'Body' => 'Hello, world!',
'ACL' => 'public-read'
));
// Print the URL to the object.
echo $result['ObjectURL'] . "\n";
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}
如果有人能帮助我,那就太好了。谢谢。--伦