AWS S3权限 - GetObjectUrl PHP拒绝访问

时间:2014-10-10 14:09:21

标签: php codeigniter amazon-web-services amazon-s3 aws-sdk

putObject对我很有用。但是,当我执行getObjectURL时,s3以拒绝访问进行响应。看看设定政策的不同方式,等等。仍然没有运气。任何帮助表示赞赏!

putObject代码:

$this->load->library('aws');

$temporary_png_path = tempnam(sys_get_temp_dir(), 'sig') . $upload_data['file_ext'];

$document_s3_key = 'profile_pictures/'.$user->id.'/profile_'.$user->id.$upload_data['file_ext'];

$resource = fopen($upload_data['full_path'], 'r');

try{
    $aws_object=$this->aws->putObject(array(
        'Bucket'      => 'tbucket',
        'Key'         => $document_s3_key,
        'SourceFile'  => $resource,
        'Body' => $resource,
        'ContentType' => 'image/jpeg'
    ));
}
catch (Exception $e)
{
    $error = "Something went wrong saving your file.\n".$e;
    echo $error;
}

getObjectURL代码:

$this->load->library('aws');
$profile_image = $this->aws->getObjectUrl('tbucket', 'profile_pictures/'.$user->id.'/'.'profile_'.$user->id.'.jpeg');
$this->data['image'] = ($profile_image == '')? "/public/images/avatar-large.jpg" : $profile_image;

AWS Permissions:

Authenticated Users => All Permissions enabled

Bucket Policy:

    {
    "Version": "2008-10-17",
    "Id": "Policynumber",
    "Statement": [
        {
            "Sid": "Stmtnumber",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::number:user/t_master"
            },
            "Action": [
                "s3:GetObjectAcl",
                "s3:GetObjectTorrent",
                "s3:GetObjectVersion",
                "s3:GetObjectVersionAcl"
            ],
            "Resource": "arn:aws:s3:::tbucket/*"
        }
    ]
}

0 个答案:

没有答案