Uploading Objects - Appending
API Description
You can use this API to append data to an object in a bucket. If there is no object with the same key value in the bucket, a new object will be created.
Method Definition
func (obsClient ObsClient) AppendObject(input *AppendObjectInput) (output *AppendObjectOutput, err error)
Method Definition If a Signed URL Is Used
func (obsClient ObsClient) AppendObjectWithSignedURL(signedURL string, actualSignedRequestHeaders http.Header, data io.Reader)) (output *AppendObjectOutput, err error)
Request Parameters
| Field | Type | Optional or Mandatory |
|---|---|---|
| input | Mandatory |
Returned Result
| Field | Type |
|---|---|
| output | |
| err | error |
Sample Code
func main() { input := &obs.AppendObjectInput{} input.Bucket = "bucketname" input.Key = "objectkey" // For the first append upload, set the upload position to 0. input.Position= 0 input.Body = strings.NewReader("Hello OBS") output, err := obsClient.AppendObject(input) if err == nil { fmt.Printf("RequestId:%s\n", output.RequestId) fmt.Printf("NextAppendPosition:%d\n", output.NextAppendPosition) // For the second append upload, specify the position to the one returned by the last append upload. input := &obs.AppendObjectInput{} input.Bucket = "bucketname" input.Key = "objectkey" input.Position= output.NextAppendPosition input.Body = strings.NewReader("Hello OBS Again") output, err := obsClient.AppendObject(input) if err == nil { fmt.Printf("RequestId:%s\n", output.RequestId) fmt.Printf("NextAppendPosition:%d\n", output.NextAppendPosition) } else { if obsError, ok := err.(obs.ObsError); ok { fmt.Println(obsError.Code) fmt.Println(obsError.Message) } else { fmt.Println(err) } } } else { if obsError, ok := err.(obs.ObsError); ok { fmt.Println(obsError.Code) fmt.Println(obsError.Message) } else { fmt.Println(err) } } }
Last Article: Uploading Objects - File-Based
Next Article: Uploading Objects - Resumable Transfer
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.