Obtaining Customized Metadata

API Description

You can use this API to Obtain customized metadata.

Method Definition

func (obsClient ObsClient) GetObject(input *GetObjectInput) (output *GetObjectOutput, err error)

Method Definition If a Signed URL Is Used

func (obsClient ObsClient) GetObjectWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetObjectOutput, err error)

Request Parameters

Field

Type

Optional or Mandatory

input

*GetObjectInput

Mandatory

Returned Results

Field

Type

output

*GetObjectOutput

err

error

Sample Code

func main() {
       // Upload the object and customize the metadata
       putObjectInput := &obs.PutObjectInput{}
       putObjectInput.Bucket = "bucketname"
       putObjectInput.Key = "objectname"
       putObjectInput.Metadata = map[string]string{"property": "property-value"}
       _, err := obsClient.PutObject(putObjectInput)
       if err != nil {
              panic(err)
       }

       input := &obs.GetObjectInput{}
       input.Bucket = "bucketname"
       input.Key = "objectname"
       // Download an object.
       output, err := obsClient.GetObject(input)
       if err == nil {
              defer output.Body.Close()
              // Obtain the customized metadata of the object.
              fmt.Printf("Metadata:%v\n", output.Metadata)
       } else if obsError, ok := err.(obs.ObsError); ok {
              fmt.Printf("Code:%s\n", obsError.Code)
              fmt.Printf("Message:%s\n", obsError.Message)
       }
}