You can call the AppendObject operation to append content to existing appendable objects.
Usage notes
In this topic, the public endpoint of the China (Hangzhou) region is used. If you want to access Object Storage Service (OSS) by using other Alibaba Cloud services in the same region as OSS, use an internal endpoint. For more information about the regions and endpoints supported by OSS, see Regions and endpoints.
In this topic, an OSSClient instance is created by using an OSS endpoint. If you want to create an OSSClient instance by using custom domain names or Security Token Service (STS), see Configuration examples for common scenarios.
If the object to which you want to append content does not exist, an appendable object is created when you call the
append_object
operation.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 is equal to the current object size, the data is appended to the end of the object.
If the object is an appendable object and the specified position from which the append operation starts is not equal to the current object size, the PositionNotEqualToLength error is returned.
If the object is not an appendable object, the ObjectNotAppendable error is returned.
Permissions
By default, an Alibaba Cloud account has full permissions on resources in the account. In contrast, RAM users and RAM roles associated with an Alibaba Cloud account initially have no permissions. To manage resources by using a RAM user or role, you must grant the required permissions via RAM policies or Bucket policies.
API | Action | Description |
AppendObject |
| Uploads an object by appending the content of the object to an existing object. |
| Specifies the tags of the object by using the x-oss-tagging header when you perform append upload. |
Examples
The following code provides an example on how to upload an object by performing append upload:
require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
# In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint.
endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
access_key_id: ENV['OSS_ACCESS_KEY_ID'],
access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
# Specify the name of the bucket. Example: examplebucket.
bucket = client.get_bucket('examplebucket')
# Replace my-object with the full path of the object. Do not include the bucket name in the full path.
bucket.append_object('my-object', 0)
# Append content to the end of the object.
next_pos = bucket.append_object('my-object', 0) do |stream|
100.times { |i| stream << i.to_s }
end
next_pos = bucket.append_object('my-object', next_pos, :file => 'local-file-1')
next_pos = bucket.append_object('my-object', next_pos, :file => 'local-file-2')
References
For more information about the API operation that you can call to perform append upload, see AppendObject.