Object permission control
Set access permission for an object.
The following code sets the object's permission to private:
1client.set_object_canned_acl(bucket_name, object_name, Http::BCE_ACL => 'private')
For specific details about permissions, please refer to BOS API Documentation [Object Access Control](BOS/API Reference/Access control.md#Object permission control).
Set access permissions for a specified user on an object
BOS provides the set_object_acl method and set_object_canned_aclmethod to set access permissions for specified users on an object. You can refer to the following code:
-
Set access permissions for specified users through
x-bce-grant-readandx-bce-grant-full-controlinset_object_canned_acl.Ruby1id_permission = "id=\"8c47a952db4444c5a097b41be3f24c94\",id=\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"" 2client.set_object_canned_acl(bucket_name, object_name, 'x-bce-grant-read' => id_permission) 3id_permission = "id=\"8c47a952db4444c5a097b41be3f24c94\",id=\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"" 4client.set_object_canned_acl(bucket_name, object_name, 'x-bce-grant-full-control' => id_permission) -
Set object access permission via
set_object_aclRuby1acl = [{'grantee' => [{'id' => 'b124deeaf6f641c9ac27700b41a350a8'}, 2 {'id' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'}], 3 'permission' => ['FULL_CONTROL'] 4}] 5client.set_object_acl(bucket_name, object_name, acl)
Note:
- The permission settings in Permission include two values:
READandFULL_CONTROL, which correspond to relevant permissions respectively.- When specifying two or more grantees, refer to the format shown in the example above. Merging arrays will result in an error.
View object permissions
The following code can be used to check the object permissions:
1client.get_object_acl(bucket_name, object_name)
The parameters available for calling in the resolution class returned by the get_object_acl method are as follows:
| Parameters | Description |
|---|---|
| accessControlList | Identify the permission list of the object |
| grantee | Identify the grantee |
| -id | Authorized person ID |
| permission | Identify the grantee permissions |
Delete object permissions
The following code can be used to delete the object permissions:
1client.delete_object_acl(bucket_name, object_name)
