Updated on 2022-02-10 GMT+08:00

PUT Bucket policy

API Description

You can use this API to set a bucket policy. If the bucket already has a policy, the policy will be overwritten by the one specified in this request.

Method Definition

func (obsClient ObsClient) SetBucketPolicy(input *SetBucketPolicyInput) (output *BaseModel, err error)

Method Definition If a Signed URL Is Used

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

Request Parameter

Field

Type

Optional or Mandatory

input

*SetBucketPolicyInput

Mandatory

Returned Result

Field

Type

output

*BaseModel

err

error

Sample Code

func main() {
       input := &obs.SetBucketPolicyInput{}
       input.Bucket = "bucketname"
       input.Policy = "your policy"
       output, err := obsClient.SetBucketPolicy(input)
       if err == nil {
              fmt.Printf("RequestId:%s\n", output.RequestId)
       } else {
              if obsError, ok := err.(obs.ObsError); ok {
                     fmt.Println(obsError.Code)
                     fmt.Println(obsError.Message)
              } else {
                     fmt.Println(err)
              }
       }
}