查看PDF

设置对象ACL

更新时间: 2019-03-13 10:20

功能说明

设置指定桶中对象的访问权限。

方法定义

  1. func (obsClient ObsClient) SetObjectAcl(input *SetObjectAclInput) (output *BaseModel, err error)

使用带授权信息URL的方法定义

  1. func (obsClient ObsClient) SetObjectAclWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error)

请求参数


参数名

类型

约束

input

*SetObjectAclInput

必选

返回结果


参数名

类型

output

*BaseModel

err

error

代码样例

  1. func main() {
  2. input := &obs.SetObjectAclInput{}
  3. input.Bucket = "bucketname"
  4. input.Key = "objectkey"
  5. input.Owner.ID = "ownerid"
  6. var grants [3]obs.Grant
  7. grants[0].Grantee.Type = obs.GranteeGroup
  8. grants[0].Grantee.URI = obs.GroupAuthenticatedUsers
  9. grants[0].Permission = obs.PermissionRead
  10.  
  11. grants[1].Grantee.Type = obs.GranteeUser
  12. grants[1].Grantee.ID = "userid"
  13. grants[1].Permission = obs.PermissionWrite
  14.  
  15. grants[2].Grantee.Type = obs.GranteeUser
  16. grants[2].Grantee.ID = "userid"
  17. grants[2].Permission = obs.PermissionRead
  18. input.Grants = grants[0:3]
  19. output, err := obsClient.SetObjectAcl(input)
  20. if err == nil {
  21. fmt.Printf("RequestId:%s\n", output.RequestId)
  22. } else {
  23. if obsError, ok := err.(obs.ObsError); ok {
  24. fmt.Println(obsError.Code)
  25. fmt.Println(obsError.Message)
  26. } else {
  27. fmt.Println(err)
  28. }
  29. }
  30. }

父主题:对象相关接口