You can append content to existing appendable objects. This topic describes how to use OSS Python SDK to perform append upload.
Considerations
The example code in this topic uses the region ID
cn-hangzhou
of China (Hangzhou) and the public endpoint by default. If you want to access OSS from other Alibaba Cloud services in the same region as OSS, use the internal endpoint. For more information about the mapping between regions and endpoints of OSS, see OSS regions and endpoints.When you call an append upload operation, if the object to which you want to append content does not exist, an appendable object is created.
If the object to which you want to append content exists:
If the object is an appendable object and the specified position from which the append operation starts equals the current object length, the content is appended to the end of the object.
If the object is an appendable object but the specified position from which the append operation starts does not equal the current object length, the PositionNotEqualToLength exception is thrown.
If the object is not an appendable object, such as a Normal object uploaded by 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, Python SDK V2 adds the AppendFile method to simulate file read and write behaviors for operating objects in buckets. The following table lists the descriptions of AppendFile and AppendObject methods:
The method name | Description |
AppendFile | Has the same capabilities as the AppendObject method Optimize fault tolerance after the object reupload fails |
AppendObject | Perform append upload to upload an object that is up to 5 GiB in size Support CRC-64 (enabled by default) Supports progress bars |
For the complete definition of the AppendObject method, see append_object.
Sample code
Common scenarios
References
For the complete sample code for append upload, see append_file.py and append_object.py.