Append upload lets you add content to the end of an existing appendable object. The final object can be up to 5 GiB.
The OSS SDK for Go V2 provides two APIs for append upload:
| API | Description | When to use |
|---|---|---|
AppendFile (recommended) | High-level API. Handles position tracking and retransmission failures automatically. | Most use cases, especially log streaming and progressive file building |
AppendObject | Low-level API. Requires manual position tracking via NextPosition. Supports progress callbacks. | When you need fine-grained control over each append request |
Prerequisites
Before you begin, ensure that you have:
The OSS SDK for Go V2 installed. See Installation
Access credentials configured as environment variables. See Configure access credentials
The
oss:PutObjectpermission on the target bucket. If you set object tags during the upload, you also needoss:PutObjectTagging
Usage notes
Sample code in this topic uses the region ID
cn-hangzhou(China (Hangzhou)). Replace it with your actual region ID. For the full list of regions and endpoints, see Regions and endpoints.By default, the public endpoint is used. To access bucket resources from another Alibaba Cloud service in the same region, use the internal endpoint instead.
If the target object does not exist, the API creates a new appendable object.
If the target object exists:
If it is an appendable object and the specified position equals the current object size, content is appended to the end.
If it is an appendable object but the specified position does not equal the current object size,
PositionNotEqualToLengthis thrown.If it is not an appendable object (for example, an object uploaded with simple upload),
ObjectNotAppendableis thrown.
Permissions
By default, an Alibaba Cloud account has full permissions. RAM users and RAM roles have no permissions by default. Grant permissions using RAM Policy or Bucket Policy.
| API | Required action | Condition |
|---|---|---|
| AppendObject | oss:PutObject | Always required |
| AppendObject | oss:PutObjectTagging | Required only when setting object tags via x-oss-tagging |
Sample code
Common scenarios
What's next
For complete sample code, see GitHub examples and the Developer Guide.
For the full
AppendFileAPI reference, see AppendFile.For the full
AppendObjectAPI reference, see AppendObject.