Uploading Objects - Streaming
API Description
Streaming upload uses io.Reader as the data source of an object. You can call ObsClient.PutObject to upload a data stream to OBS.
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 Parameters
| Field | Type | Optional or Mandatory |
|---|---|---|
| input | Mandatory |
Returned Results
| Field | Type |
|---|---|
| output | |
| err | error |
Sample Code
Uploading a Character String
func main() { 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) } else if obsError, ok := err.(obs.ObsError); ok { fmt.Printf("Code:%s\n", obsError.Code) fmt.Printf("Message:%s\n", obsError.Message) } }
Uploading a File Stream
func main() { input := &obs.PutObjectInput{} input.Bucket = "bucketname" input.Key = "objectname" fd, _ := os.Open("localfile") input.Body = fd output, err := obsClient.PutObject(input) if err == nil { fmt.Printf("RequestId:%s\n", output.RequestId) fmt.Printf("ETag:%s\n", output.ETag) } else if obsError, ok := err.(obs.ObsError); ok { fmt.Printf("Code:%s\n", obsError.Code) fmt.Printf("Message:%s\n", obsError.Message) } }
- To upload a large file, you are advised to use Multipart Upload Overview.
- The content to be uploaded cannot exceed 5 GB.
Last Article: Object Upload Overview
Next Article: Uploading Objects - File-Based
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.