All Products
Search
Document Center

Object Storage Service:Append upload (iOS SDK)

Last Updated:Nov 29, 2025

Append upload uses the Object Storage Service (OSS) `AppendObject` API operation to append content to an existing appendable object.

Note

Objects uploaded using the `AppendObject` operation are appendable objects. Objects uploaded using the `PutObject` operation are normal objects.

Considerations

  • Before you use the examples in this topic, you must create an OSSClient instance using a custom domain name or Security Token Service (STS). For more information, see Initialization (iOS SDK).

    Note

    The region of the bucket that you create is determined by the endpoint specified in the initialization configuration.

  • In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.

  • If the object does not exist, calling the AppendObject operation creates a new appendable object.

  • If the object already exists:

    • If the object is an appendable object and the specified append position matches the current length of the object, the content is added to the end of the object.

    • If the object is an appendable object but the specified append position does not match the current length of the object, a PositionNotEqualToLength exception is thrown.

    • If the object is not an appendable object, such as a normal object that is uploaded using simple upload, the ObjectNotAppendable exception is thrown.

  • The CopyObject operation is not supported for appendable objects.

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

oss:PutObject

You can call this operation to upload an object by appending the object to an existing object.

oss:PutObjectTagging

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 provides an example of how to perform an append upload.

OSSAppendObjectRequest * append = [OSSAppendObjectRequest new];
// Configure the required fields. `bucketName` specifies the name of the bucket. `objectKey`, which is equivalent to `objectName`, specifies the full path of the object to which you want to append data. The path must include the file extension, for example, `abc/efg/123.jpg`.
append.bucketName = @"<bucketName>";
append.objectKey = @"<objectKey>";
// Specify the position for the first append upload.
append.appendPosition = 0; 
NSString * docDir = [self getDocumentDirectory];
append.uploadingFileURL = [NSURL fileURLWithPath:@"<yourLocalFilePath>"];
// The following fields are optional.
append.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
    NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
};
// append.contentType = @"";
// append.contentMd5 = @"";
// append.contentEncoding = @"";
// append.contentDisposition = @"";
OSSTask * appendTask = [client appendObject:append];
[appendTask continueWithBlock:^id(OSSTask *task) {
    NSLog(@"objectKey: %@", append.objectKey);
    if (!task.error) {
        NSLog(@"append object success!");
        OSSAppendObjectResult * result = task.result;
        NSString * etag = result.eTag;
        long nextPosition = result.xOssNextAppendPosition;
    } else {
        NSLog(@"append object failed, error: %@" , task.error);
    }
    return nil;
}];

References