
# 设置对象ACL
#### 功能说明
设置指定桶中对象的访问权限。
#### 方法定义
```
1. ObsClient->setObjectAcl(array $parameter)
2. ObsClient->setObjectAclAsync(array $parameter, callable $callback)
```
#### 请求参数
| **字段名**    ||| **类型**            | **约束**                           | **说明**                                                                               |
|:--|---|---|:---|:---|:---|
| Bucket     ||| string            | 必选                               | 桶名。                                                                                  |
| Key        ||| string            | 必选                               | 对象名。                                                                                 |
| VersionId  ||| string            | 可选                               | 对象的版本号。                                                                              |
| ACL        ||| string            | 可选                               | [预定义访问策略](https://support.huaweicloud.com/api-obs_php_sdk_api_zh/obs_38_0204.html)。  |
| Owner      ||| associative array | 可选                               | 对象的所有者。                                                                              |
| - | ID      || string            | 必选                               | 对象所有者的DomainId。                                                                      |
| Delivered  ||| boolean           | 可选                               | 桶的ACL是否向桶内对象传递。                                                                      |
| Grants     ||| indexed array     | 可选                               | 被授权用户权限信息列表。                                                                         |
| - | Grantee || Object            | 必选                               | 被授权用户。                                                                               |
| - | - | Type | string            | 必选                               | 被授权的[用户类型](https://support.huaweicloud.com/api-obs_php_sdk_api_zh/obs_38_0203.html)。 |
| - | - | ID   | string            | 如果Type为"CanonicalUser"则必选，否则必须为空 | 被授权用户的DomainId。                                                                      |
| - | - | URI  | string            | 如果Type为"Group"则必选，否则必须为空         | 被授权的[用户组](https://support.huaweicloud.com/api-obs_php_sdk_api_zh/obs_38_0202.html)。  |
| - | Permission || string            | 必选                               | 被授予的[权限](https://support.huaweicloud.com/api-obs_php_sdk_api_zh/obs_38_0201.html)。   |
   
![](https://support.huaweicloud.com/api-obs_php_sdk_api_zh/public_sys-resources/note_3.0-zh-cn.png)
- Owner和Grants必须配套使用，且与ACL互斥。当设置了这两个字段时，不能设置ACL；反之，当设置了ACL时，不能设置Owner和Grants。
- Owner、Grants与ACL不能全为空。
 
#### 返回结果
| **字段名**        | **类型**  | **说明**         |
|:---|:---|:---|
| HttpStatusCode | integer | HTTP状态码。       |
| Reason         | string  | HTTP文本描述。      |
| RequestId      | String  | OBS服务端返回的请求ID。 |
   
#### 代码样例
```
try {
       $resp = $obsClient->setObjectAcl( [ 
                     'Bucket' => 'bucketname',
                     'Key' => 'objectkey',
                     'Owner' => ['ID' => 'ownerid'],
                     'Grants' => [
                           ['Grantee' => ['Type' => 'CanonicalUser', 'ID' => 'userid'], 'Permission' => ObsClient::PermissionRead],
                           ['Grantee' => ['Type' => 'CanonicalUser', 'ID' => 'userid'], 'Permission' => ObsClient::PermissionWriteAcp],
                           ['Grantee' => ['Type' => 'Group', 'URI' => ObsClient::GroupAuthenticatedUsers], 'Permission' => ObsClient::PermissionWriteAcp],
                           ['Grantee' => ['Type' => 'Group', 'URI' => ObsClient::GroupAuthenticatedUsers], 'Permission' => ObsClient::PermissionRead],
                     ]
       ] );
       printf ( "RequestId:%s\n", $resp ['RequestId'] );
} catch ( Obs\Common\ObsException $obsException ) {
       printf ( "ExceptionCode:%s\n", $obsException->getExceptionCode () );
       printf ( "ExceptionMessage:%s\n", $obsException->getExceptionMessage () );
}
```
