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

PUT Object

API Description

You can use this API to upload an object to a specified bucket.

Method Definition

func (obsClient ObsClient) PutObject(input *PutObjectInput) (output *PutObjectOutput, err error)

Method Definition If a Signed URL Is Used

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

Request Parameter

Field

Type

Optional or Mandatory

input

*PutObjectInput

Mandatory

Returned Result

Field

Type

output

*PutObjectOutput

err

error

Sample Code

func main() {
       input := &obs.PutObjectInput{}
       input.Bucket = "bucketname"
       input.Key = "objectkey"
       input.Body = strings.NewReader("Hello OBS")
       output, err := obsClient.PutObject(input)

       if err == nil {
              fmt.Printf("RequestId:%s\n", output.RequestId)
              fmt.Printf("ETag:%s, StorageClass:%s\n", output.ETag, output.StorageClass)
       } else {
              if obsError, ok := err.(obs.ObsError); ok {
                     fmt.Println(obsError.Code)
                     fmt.Println(obsError.Message)
              } else {
                     fmt.Println(err)
              }
       }
}