【发布时间】:2020-02-01 03:03:35
【问题描述】:
我之前已经遇到过两个错误,这是我每次尝试将文件上传到我的 s3 存储桶时的最新错误:
PUT https://cactustestphp.s3.us-west-1.amazonaws.com/videouploads/my-image.png` resulted in a `403
Forbidden` response: AccessDeniedAccess Denied33D5F8 (truncated...) AccessDenied (client):
Access Denied - AccessDeniedAccess
如果有人知道我为什么会遇到这个问题,请随时回复!我已经在下面发布了我的用户和存储桶策略,以防出现任何明显的错误。
这是我的 php 代码:
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
'version' => 'latest',
'region' => 'US-West',
'credentials' => [
'key' => 'garbage',
'secret' => 'garbage'
]
]);
$bucketName = 'garbage';
$file_Path = __DIR__ . '/my-image.png';
$key = basename($file_Path);
// Upload a publicly accessible file. The file size and type are determined by the SDK.
try {
$result = $s3->putObject([
'Bucket' => $bucketName,
'Key' => 'videouploads/' . $key,
'Body' => fopen($file_Path, 'r'),
'ACL' => 'public-read',
]);
echo $result->get('ObjectURL');
} catch (Aws\S3\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n";
echo $e->getMessage();
}
?>
我的存储桶政策:
{
"Version": "2012-10-17",
"Id": "Policy1488494182833",
"Statement": [
{
"Sid": "Stmt1488493308547",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::056984788586:user/cactustest123"
},
"Action": [
"s3:ListBucket",
"s3:ListBucketVersions",
"s3:GetBucketLocation",
"s3:Get*",
"s3:Put*"
],
"Resource": "arn:aws:s3:::cactustestphp"
}
]
}
我的用户政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:PutObject",
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::*"
]
}
]
}
【问题讨论】:
标签: php amazon-web-services amazon-s3 sdk