Append upload lets you add content to the end of an appendable object using the AppendObject method.
Notes
In this topic, the public endpoint of the China (Hangzhou) region is used. To access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. For details about supported regions and endpoints, 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 file does not exist, the
Bucket#append_objectmethod creates an appendable object.If the file already exists:
If the file is an appendable object and the specified append position matches the current length of the file, the content is appended to the end of the file.
If the file is an appendable object but the specified append position does not match the current length of the file, a PositionNotEqualToLength exception is thrown.
If the file is not an appendable object, such as a normal object uploaded by a simple upload, an 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 policies.
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. |
Sample code
The following code shows how to perform an append upload.
require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
# The China (Hangzhou) region is used as an example. Specify the actual region.
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 set.
access_key_id: ENV['OSS_ACCESS_KEY_ID'],
access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
# Specify the bucket name, for example, examplebucket.
bucket = client.get_bucket('examplebucket')
# Specify the full path of the object. The full path cannot contain the bucket name.
bucket.append_object('my-object', 0)
# Append content to the end of the file.
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 AppendObject API operation, see AppendObject.