Append upload lets you append content directly to the end of an existing appendable object. This topic describes how to perform an append upload using the OSS SDK for Go.
Usage notes
The sample code in this topic uses the region ID
cn-hangzhoufor the China (Hangzhou) region. By default, the public Endpoint is used to access resources in a bucket. If you want to access resources in the bucket using other Alibaba Cloud services in the same region in which the bucket is located, you can use the internal Endpoint. For more information about OSS regions and endpoints, see Regions and endpoints.In this topic, access credentials are read from environment variables. For more information about how to configure access credentials, see Configure access credentials.
If the file to which you want to append content does not exist, an appendable object is created when you call an append upload API operation.
If the file to which you want to append content exists:
If the file is an appendable object and the specified append position is the same as the current length of the file, content is appended to the end of the file.
If the file is an appendable object but the specified append position is not the same as the current length of the file, the PositionNotEqualToLength exception is thrown.
If the file is not an appendable object, such as a normal object uploaded using simple upload, the ObjectNotAppendable exception is thrown.
Permissions
By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM Policy or Bucket Policy.
API | Action | Definition |
AppendObject |
| You can call this operation to upload an object by appending the object to an existing object. |
| When uploading an object by appending the object to an existing object, if you specify object tags through x-oss-tagging, this permission is required. |
Method definition
For append upload scenarios, the OSS SDK for Go provides the new AppendFile operation to simulate file read and write behaviors for objects in a bucket. The following table describes the AppendFile and AppendObject operations.
Operation name | Description |
Client.AppendObject | Performs an append upload. The final object can be up to 5 GiB in size. Supports CRC-64 data integrity check (enabled by default). Supports progress bars. The request body is of the io.Reader type. If the io.Seeker type is supported, retransmission is available upon failure. This operation is not idempotent, and retransmission may fail. |
Client.AppendFile | Provides the same capabilities as the Client.AppendObject operation. Optimizes fault tolerance for retransmission failures. Includes the AppendOnlyFile operation. AppendOnlyFile.Write AppendOnlyFile.WriteFrom |
Sample code
Common scenarios
References
For the complete sample code for append upload, see GitHub examples and Developer Guide.
For more information about the premium API operation for append upload, see AppendFile.
For more information about the basic API operation for append upload, see AppendObject.