获取对象访问权限

您可以使用 getObjectAcl 接口获取对象访问的权限。以下代码展示如何获取对象的访问权限:

$bucket = '<your-bucket-name>';
$keyname = '<your-object-key>';
try {
    $resp = $s3Client->getObjectAcl([
        'Bucket' => $bucket,
        'Key' => $keyname,
    ]);
    echo "Succeed in retrieving object ACL as follows: \n";
    //打印获取的对象 owner displayname,ID 以及访问权限信息
    echo 'Owner DisplayName: ' . $resp['Owner']['DisplayName'] . "\n";
    echo 'Owner ID: '          . $resp['Owner']['ID']          . "\n";
    foreach ($resp['Grants'] as $grant) {
        echo "Grant: \n";
        foreach($grant['Grantee'] as $k=>$val)
        {
            echo $k . ": " . $val . "\n";
        }
        echo 'Permission: ' . $grant['Permission'] . "\n";
    }
} catch (AwsException $e) {
    echo $e->getMessage();
    echo "\n";
}