Modifying an Object

API Description

You can use this API to modify the content of an object in a parallel file system from the specified position.

This API is currently available only for parallel file systems, not for object buckets. For details about how to create a parallel file system, see Creating a Bucket.

Method Definition

func (obsClient ObsClient) ModifyObject(input *ModifyObjectInput) (output *ModifyObjectOutput, err error)

Method Definition If a Signed URL Is Used

func (obsClient ObsClient) ModifyObjectWithSignedURL(signedURL string, actualSignedRequestHeaders http.Header, data io.Reader)) (output *ModifyObjectOutput, err error)

Request Parameters

Field

Type

Optional or Mandatory

input

*ModifyObjectInput

Mandatory

Returned Result

Field

Type

output

*ModifyObjectOutput

err

error

Sample Code

func main() {
       // Common upload used for subsequent modification
       input := &obs.PutObjectInput{}
       input.Bucket = "bucketname"
       input.Key = "objectname"
       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\n", output.ETag)
              // Modify the uploaded object from position 0.
              input2 := &obs.ModifyObjectInput{}
              input2.Bucket = "bucketname"
              input2.Key = "objectname"
              input2.Position = 0
              input2.Body = strings.NewReader("Modify Hello OBS")
              output2, err := obsClient.ModifyObject(input2)
              if err == nil {
                  fmt.Printf("RequestId:%s\n", output.RequestId)
                  fmt.Printf("ETag:%s\n", output2.ETag)
              } else if obsError, ok := err.(obs.ObsError); ok {
                  fmt.Printf("Code:%s\n", obsError.Code)
                  fmt.Printf("Message:%s\n", obsError.Message)
              }
       } else if obsError, ok := err.(obs.ObsError); ok {
              fmt.Printf("Code:%s\n", obsError.Code)
              fmt.Printf("Message:%s\n", obsError.Message)
       }
}