Updated on 2022-09-16 GMT+08:00

Appendable Upload

Appendable upload allows you to upload an object in appending mode and then append data to the object. You can call appendObject to perform appendable upload. Sample code is as follows:
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"FileName" ofType:@"FileSuffix"];
    NSFileManager *manager = [NSFileManager defaultManager];
    NSDictionary *fileDic = [manager attributesOfItemAtPath:filePath error:nil];
    unsigned long long size = [[fileDic objectForKey:NSFileSize] longLongValue];
    int filesize = size;
    //Create an object in appendable mode.
    OBSAppendObjectWithFileRequest *request = [[OBSAppendObjectWithFileRequest alloc] initWithBucketName:@"bucketName" objectKey:@"objectname" uploadFilePath:filePath];
    request.position = [NSNumber numberWithFloat:0];
    
    request.uploadProgressBlock =  ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
        NSLog(@"%0.1f%%",(float)floor(totalBytesSent*10000/totalBytesExpectedToSend)/100);
        
    };
    [client appendObject:request completionHandler:^(OBSAppendObjectResponse *response, NSError *error) {
        NSLog(@"%@",response);
        //Start position for next appending
       Int position = response.nextPosition;
    }];
    
    //Append data to the object.
    OBSAppendObjectWithFileRequest *request = [[OBSAppendObjectWithFileRequest alloc] initWithBucketName:@"bucketName" objectKey:@"objectname" uploadFilePath:filePath];
    request.position = [NSNumber numberWithFloat:size];
    
    request.uploadProgressBlock =  ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {
        NSLog(@"%0.1f%%",(float)floor(totalBytesSent*10000/totalBytesExpectedToSend)/100);
        
    };
    [client appendObject:request completionHandler:^(OBSAppendObjectResponse *response, NSError *error) {
        NSLog(@"%@",response);
        //Start position for next appending
        Int position = response.nextPosition;
    }];
  • Objects uploaded using putObject, referred to as normal objects, can overwrite objects uploaded using appendObject, referred to as appendable objects. Data cannot be appended to an appendable object anymore once the object has been overwritten by a normal object.
  • When you upload an object for the first time in appendable mode, an exception will be thrown (status code 409) if a normal object with the same name exists.
  • The ETag returned for an appendable upload is the ETag for the uploaded content, rather than that of the whole object.
  • Data appended each time can be up to 5 GB, and 10000 times of appendable uploads can be performed on a single object.
  • After an appendable upload is successful, you can use response.nextPosition or call getObjectMetadata to get the start position for next appending.