更新时间:2024-03-05 GMT+08:00
分享

追加上传

追加上传可实现对同一个对象追加数据内容的功能。您可以通过appendObject进行追加上传。示例代码如下
    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;
    //第一次追加上传
    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);
        //下次上传位置
       Int position = response.nextPosition;
    }];
    
    //第二次追加上传
    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);
        //下次上传位置
        Int position = response.nextPosition;
    }];
  • putObject上传的对象可覆盖appendObject上传的对象,覆盖后对象变为普通对象,不可再进行追加上传。
  • 第一次调用追加上传时,如果已存在同名的普通对象,则会抛出异常(HTTP状态码为409)。
  • 追加上传返回的ETag是当次追加数据内容的ETag,不是完整对象的ETag。
  • 单次追加上传的内容不能超过5GB,且最多支持10000次追加上传。
  • 追加上传成功后,可通过response.nextPosition获取下次追加上传的位置;或者通过getObjectMetadata接口获取下次追加上传的位置。
分享:

    相关文档

    相关产品