You can call the AppendObject operation of Object Storage Service (OSS) to append content to an appendable object. This is called append upload.

Usage notes

  • In this topic, the public endpoint of the China (Hangzhou) region is used. If you want to access 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 STS, see Create an OSSClient instance.
  • The oss:PutObject permission is required to use append upload. For more information, see Attach a custom policy to a RAM user.
  • If the object to which you want to append content does not exist, an appendable object is created when you call the AppendObject 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 object 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.
  • The CopyObject operation cannot be performed on appendable objects.

Sample code

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

OSSAppendObjectRequest * append = [OSSAppendObjectRequest new];
// Configure the required fields. bucketName indicates the name of the bucket. objectKey is equivalent to objectName that indicates the full path of the object you want to upload to OSS by using append upload. The path must include the extension of the object. For example, you can set objectKey to abc/efg/123.jpg. 
append.bucketName = @"<bucketName>";
append.objectKey = @"<objectKey>";
// Specify the position from which the first append operation starts. 
append.appendPosition = 0; 
NSString * docDir = [self getDocumentDirectory];
append.uploadingFileURL = [NSURL fileURLWithPath:@"<filepath>"];
// Configure the optional fields. 
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

For more information about the API operation that you can call to perform append upload, see AppendObject.