• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python SDK)
  4. Objects-Related APIs
  5. PUT Object acl

PUT 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 Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

objectKey

str

Mandatory

Object name

acl

ACL

Optional

Object ACL

versionId

str

Optional

Object version ID

aclControl

str

Optional

Pre-defined access policy. Possible values are:

  • private
  • public-read
  • public-read-write
  • authenticated-read
  • bucket-owner-read
  • bucket-owner-full-control
NOTE:

acl is mutually exclusive with aclControl.

Returned Result

Type

Description

GetResult

SDK common result object

Sample Code

try:
    from com.obs.models.acl import ACL 
    from com.obs.models.owner import Owner 
    from com.obs.models.grant import Grant, Permission 
    from com.obs.models.grantee import Grantee, Group 
    owner = Owner(owner_id='ownerid', owner_name='ownername') 
     
    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_USERE), permission=Permission.READ)  
     
    grant2 = Grant(grantee=Grantee(group=Group.ALL_USERE), 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('status:', resp.status)
except:
    import traceback
    print(traceback.format_exc())