You can use AppendObject to append content to appendable objects that are uploaded.

Usage notes

When you call AppendObject to upload an object, take note of the following items:

  • If the object to append does not exist, an append object is created.
  • If the object to append is an existing append 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 to append is a non-append object, the ObjectNotAppendable error is returned.
  • The CopyObject operation cannot be performed on append objects.

For more information about how to perform append upload, see AppendObject. For the complete code of append upload, visit GitHub.

Sample codes

The following code provides an example on how to perform append upload:

using Aliyun.OSS;
// The endpoint of the China (Hangzhou) region is used in this example. Specify the actual endpoint.
var endpoint = "<yourEndpoint>";
// Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS because the account has permissions on all API operations. We recommend that you use your RAM user's credentials to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console.
var accessKeyId = "<yourAccessKeyId>";
var accessKeySecret = "<yourAccessKeySecret>";
// Configure the bucket name.
var bucketName = "<yourBucketName>";
// Configure the object name. The object name indicates the complete path of the object excluding the bucket name. Example: example/folder/abc.jpg.
var objectName = "<yourObjectName>";
// Configure the name of the local file you want to upload. Specify the complete path of the local file. Example: /users/local/abc.jpg.
var localFilename = "<yourLocalFilename>";
// Create an OSSClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
// If the object is appended for the first time, the append position is 0. The position for the next append operation is included in the response. The position from which the next append operation starts is the current length of the object.
long position = 0;
try
{
    var metadata = client.GetObjectMetadata(bucketName, objectName);
    position = metadata.ContentLength;
}
catch (Exception) { }
try
{
    using (var fs = File.Open(localFilename, FileMode.Open))
    {
        var request = new AppendObjectRequest(bucketName, objectName)
        {
            ObjectMetadata = new ObjectMetadata(),
            Content = fs,
            Position = position
        };
        // Perform the append operation.
        var result = client.AppendObject(request);
        // Configure the position from which the append operation starts.
        position = result.NextAppendPosition;
        Console.WriteLine("Append object succeeded, next append position:{0}", position);
    }
    // Obtain the position for the next append operation and perform the second append operation.
    using (var fs = File.Open(localFilename, FileMode.Open))
    {
        var request = new AppendObjectRequest(bucketName, objectName)
        {
            ObjectMetadata = new ObjectMetadata(),
            Content = fs,
            Position = position
        };
        var result = client.AppendObject(request);
        position = result.NextAppendPosition;
        Console.WriteLine("Append object succeeded, next append position:{0}", position);
    }
}
catch (Exception ex)
{
    Console.WriteLine("Append object failed, {0}", ex.Message);
}

For more information about the naming conventions for buckets, see bucket. For more information about the naming conventions for objects, see object.