我正在尝试上传AWS s3
上的文件。但获得访问被拒绝错误。
这是我的代码
$result = $this->Amazon->S3->putObject(array(
'Bucket' => 'mycustom.testing',
'Signature' => 'v4',
'ACL' => 'public-read',
'Key' => $key,
'ServerSideEncryption' => 'AES256',
'SourceFile' => $tmp,
'Body' => $tmp,
'CacheControl' => 'max-age=172800',
'debug' => true
// 'ContentType' => $_FILES['data']['type']['User']['image'],
));
我的存储桶政策是
{
"Version": "2012-10-17",
"Id": "http referer policy example",
"Statement": [
{
"Sid": "Allow get requests referred by www.myweb.co and myweb.co",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::mycustom.testing/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://www.myweb.co/*",
"http://myweb.co/*"
]
}
}
},
{
"Sid": "DenyUnEncryptedObjectUploads",
"Effect": "Deny",
"Principal": "*",
"Action": ["s3:PutObject"],
"Resource": "arn:aws:s3:::mycustom.testing/*",
"Condition": {
"StringNotEquals": {
"s3:x-amz-server-side-encryption": "AES256"
}
}
}
]
}
如果我删除了'ACL' => 'public-read',
,那么文件会上传,但之后我无法通过网址看到它。我尝试添加s3:PutObjectAcl
,但后来显示了存储桶策略错误,我无法保存策略。