Updated on 2024-06-18 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); }; __block NSString* nextPosition = nil; [client appendObject:request completionHandler:^(OBSAppendObjectResponse *response, NSError *error) { NSLog(@"%@",response); //Start position for next appending NSDictionary *temp = [response headers]; nextPosition = [temp valueForKey:@"x-obs-next-append-position"]; NSLog(@"nextPosition:%@", nextPosition); }]; //Append data to the object. request = [[OBSAppendObjectWithFileRequest alloc] initWithBucketName:@"bucketName" objectKey:@"objectname" uploadFilePath:filePath]; int nextPositionInt = [nextPosition intValue]; request.position = [NSNumber numberWithInt:nextPositionInt]; 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 NSDictionary *temp = [response headers]; nextPosition = [temp valueForKey:@"x-obs-next-append-position"]; NSLog(@"nextPosition:%@", 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 reported (HTTP status code 409) if a common object with the same name is already present.
- 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.
- To obtain the next append position after an append upload is complete, use:
NSDictionary *temp = [response headers];NSString* nextPosition = [temp valueForKey:@"x-obs-next-append-position"]; You can also use getObjectMetadata to get the position for the next append upload.
Parent topic: Object Upload
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.