Setting Object ACL
API Description
You can use this API to set the ACL for an object in a specified bucket.
Method Definition
ObsClient.setObjectAcl(bucketName, objectKey, acl, versionId, aclControl)
Request Parameters
| Field | Type | Optional or Mandatory | Description |
|---|---|---|---|
| bucketName | str | Mandatory | Bucket name |
| objectKey | str | Mandatory | Object name |
| acl | Optional | Object ACL | |
| versionId | str | Optional | Object version ID |
| aclControl | str | Optional |
acl and aclControl are mutually exclusive.
Returned Results
| Type | Description |
|---|---|
| SDK common result object |
Sample Code
try:
from obs import ACL
from obs import Owner
from obs import Grant, Permission
from obs import Grantee, Group
owner = Owner(owner_id='ownerid')
grantee = Grantee(grantee_id='userid')
grant0 = Grant(grantee=grantee, permission=Permission.READ)
grant0 = Grant(grantee=grantee, permission=Permission.WRITE)
grant1 = Grant(grantee=Grantee(group=Group.ALL_USERS), permission=Permission.READ)
grant2 = Grant(grantee=Grantee(group=Group.ALL_USERS), permission=Permission.WRITE)
acl = ACL(owner=owner, grants=[grant0, grant1, grant2])
resp = obsClient.setObjectAcl('bucketname', 'objectkey', acl=acl)
if resp.status < 300:
print('requestId:', resp.requestId)
else:
print('errorCode:', resp.errorCode)
print('errorMessage:', resp.errorMessage)
except:
import traceback
print(traceback.format_exc()) Last Article: Modifying Object Metadata
Next Article: Obtaining Object ACL Information
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.