Upload objects (Go SDK V2)
Upload objects to a versioning-enabled bucket using OSS Go SDK V2. This topic covers three upload methods — simple upload, append upload, and multipart upload — and explains how versioning affects each.
Prerequisites
Before you begin, make sure you have:
A versioning-enabled or versioning-suspended OSS bucket
The
oss:PutObjectpermission. For details, see Attach a custom policy to a RAM userAccess credentials configured in environment variables. For details, see Configure access credentials
Usage notes
All examples use the China (Hangzhou) region (
cn-hangzhou) with a public endpoint. To access OSS from another Alibaba Cloud service in the same region, use an internal endpoint. For details, see Regions and endpoints.Credentials are read from environment variables in all examples.
How versioning affects uploads
The bucket's versioning state determines what version ID OSS assigns to each uploaded object:
| Upload method | Versioning-enabled bucket | Versioning-suspended bucket |
|---|---|---|
| Simple upload (PutObject) | OSS generates a unique version ID and returns it in the x-oss-version-id response header | OSS assigns a null version ID; uploading an object with the same name overwrites the existing object. As a result, each object has only a single version with a null version ID |
| Append upload (AppendObject) | Only the current version of an appendable object can be appended to; previous versions cannot | Not applicable (AppendObject versioning-suspended behavior is not documented) |
| Multipart upload (CompleteMultipartUpload) | OSS generates a unique version ID and returns it in the x-oss-version-id response header | Not applicable (multipart upload versioning-suspended behavior is not documented) |
API reference
Simple upload: Client.PutObject
Append upload: Client.AppendObject
Multipart upload: Client.InitiateMultipartUpload, Client.UploadPart, Client.CompleteMultipartUpload