这是我在“https://s3.ap-south-1.amazonaws.com/infosecure.buck/uploads/5th.jpg”上执行"PutObject"时出错的错误; AWS HTTP错误:客户端错误: PUT https://s3.ap-south-1.amazonaws.com/infosecure.buck/uploads/5th.jpg
导致 403 Forbidden
响应:AccessDeniedAccess Denied69DC61(截断...)AccessDenied(客户端):访问被拒绝 - AccessDeniedAccess Denied69DC6155E0F5042AHg2jvV2iLEsOHnmsvxM2meASpYr9Z3I6zPxEPedneHixIaPZpfESW1 / SCO0UwlVnTKBXwkatE0M =
<?php
use Aws\S3\Exception\S3Exception;
require 'app/start.php';
if(isset($_FILES['file']))
{
$file=$_FILES['file'];
$name= $file['name'];
$tmp_name = $file['tmp_name'];
$extension = explode('.',$name);
$extension=strtolower(end($extension));
$key = md5(uniqid());
$tmp_file_name= "{$key}.{$extension}";
$tmp_file_path = "files/{$tmp_file_name}";
move_uploaded_file($tmp_name,$tmp_file_path);
try{
$s3->putObject([
'Bucket' => $config['s3']['bucket'],
'Key' => "uploads/{$name}",
'Body' => fopen($tmp_file_path,'rb'),
'ACL' => 'public-read'
]);
unlink($tmp_file_path);}
catch(S3Exception $e)
{
echo $e->getmessage();
}
}
?>
这是我的桶政策
{“Version”:“2012-10-17”,“Statement”:[{“Effect”:“Allow”,“Principal”:{“AWS”:“arn:aws:iam :: 601825519382:user / admin- infosecure“},”Action“:”s3:*“,”资源“:”arn:aws:s3 ::: infosecure.buck“}]}
1 回答
似乎是一个许可问题 .
如果您通过本地计算机访问,请确保您的IAM用户具有对存储桶的写入权限 .
如果在EC2实例上运行此代码,请确保Instance Role具有对此存储桶的写访问权 .