API | 操作名 | 操作描述 |
简单上传对象 | 上传一个对象至存储桶 |
API | 操作名 | 操作描述 |
查询分块上传 | 查询正在进行中的分块上传信息 | |
初始化分块上传 | 初始化分块上传操作 | |
上传分块 | 分块上传对象 | |
查询已上传块 | 查询特定分块上传操作中的已上传的块 | |
完成分块上传 | 完成整个文件的分块上传 | |
终止分块上传 | 终止一个分块上传操作并删除已上传的块 |
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];/** 本地文件路径,请确保 URL 是以 file:// 开头,格式如下 :1. [NSURL URLWithString:@"file:////var/mobile/Containers/Data/Application/DBPF7490-D5U8-4ABF-A0AF-CC49D6A60AEB/Documents/exampleobject"]2. [NSURL fileURLWithPath:@"/var/mobile/Containers/Data/Application/DBPF7490-D5U8-4ABF-A0AF-CC49D6A60AEB/Documents/exampleobject"]*/NSURL* url = [NSURL fileURLWithPath:@"文件的URL"];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = @"exampleobject";// 需要上传的对象内容。可以传入NSData*或者NSURL*类型的变量put.body = url;// 监听上传进度[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent 本次要发送的字节数(一个大文件可能要分多次发送)// totalBytesSent 已发送的字节数// totalBytesExpectedToSend 本次上传要发送的总字节数(即一个文件大小)}];// 监听上传结果[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// 在上传结果 result.location 中获取上传文件的下载链接NSString * fileUrl = result.location;// 获取文件crc64NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[put setInitMultipleUploadFinishBlock:^(QCloudInitiateMultipartUploadResult *multipleUploadInitResult,QCloudCOSXMLUploadObjectResumeData resumeData) {// 在初始化分块上传完成以后会回调该 block,在这里可以获取 resumeData,uploadidNSString* uploadId = multipleUploadInitResult.uploadId;}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = "exampleobject";// 需要上传的对象内容。可以传入NSData*或者NSURL*类型的变量put.body = NSURL.fileURL(withPath: "Local File Path") as AnyObject;// 监听上传结果put.setFinish { (result, error) in// 获取上传结果if let result = result {// 文件的 etaglet eTag = result.eTag// 文件下载链接let location = result.location;// 获取文件crc64let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// 监听上传进度put.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent 本次要发送的字节数(一个大文件可能要分多次发送)// totalBytesSent 已发送的字节数// totalBytesExpectedToSend 本次上传要发送的总字节数(即一个文件大小)};// 设置上传参数put.initMultipleUploadFinishBlock = {(multipleUploadInitResult, resumeData) in// 在初始化分块上传完成以后会回调该 block,在这里可以获取 resumeData,以及 uploadIdif let multipleUploadInitResult = multipleUploadInitResult {let uploadId = multipleUploadInitResult.uploadId}}QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = @"exampleobject";// 需要上传的对象内容。可以传入NSData*或者NSURL*类型的变量put.body = [@"My Example Content" dataUsingEncoding:NSUTF8StringEncoding];// 监听上传进度[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent 新增字节数// totalBytesSent 本次上传的总字节数// totalBytesExpectedToSend 本地上传的目标字节数}];// 监听上传结果[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// 在上传结果 result.location 中获取上传文件的下载链接NSString * fileUrl = result.location;// 获取文件crc64NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = "exampleobject";// 需要上传的对象内容let dataBody:NSData = "wrwrwrwrwrw".data(using: .utf8)! as NSData;put.body = dataBody;// 监听上传结果put.setFinish { (result, error) in// 获取上传结果if let result = result {// 文件的 etaglet eTag = result.eTag// 文件下载链接let location = result.location;// 获取文件crc64let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// 监听上传进度put.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent 新增字节数// totalBytesSent 本次上传的总字节数// totalBytesExpectedToSend 本地上传的目标字节数};QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);
NSError *error;NSData *resmeData = [put cancelByProductingResumeData:&error];
QCloudCOSXMLUploadObjectRequest *resumeRequest = [QCloudCOSXMLUploadObjectRequest requestWithRequestData:resmeData];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:resumeRequest];
//丢弃该上传[put abort:^(id outputObject, NSError *error) {}];
var error : NSError?;var uploadResumeData:Data = put.cancel(byProductingResumeData:&error) as Data;
var resumeRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>.init(request: uploadResumeData);QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(resumeRequest);
//丢弃该上传put.abort { (outputObject, error) in}
for (int i = 0; i<20; i++) {QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = [NSString stringWithFormat:@"exampleobject-%d",i];// 需要上传的对象内容。可以传入NSData*或者NSURL*类型的变量put.body = [@"My Example Content" dataUsingEncoding:NSUTF8StringEncoding];// 监听上传进度[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent 本次要发送的字节数(一个大文件可能要分多次发送)// totalBytesSent 已发送的字节数// totalBytesExpectedToSend 本次上传要发送的总字节数(即一个文件大小)}];// 监听上传结果[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// 在上传结果 result.location 中获取上传文件的下载链接NSString * fileUrl = result.location;// 获取文件crc64NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];}
for i in 1...10 {let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = "exampleobject-".appendingFormat("%d", i);// 需要上传的对象内容let dataBody:NSData = "wrwrwrwrwrw".data(using: .utf8)! as NSData;put.body = dataBody;// 监听上传结果put.setFinish { (result, error) in// 获取上传结果if let result = result {// 文件的 etaglet eTag = result.eTag// 文件的下载链接let location = result.location;// 获取文件crc64let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// 监听上传进度put.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent 本次要发送的字节数(一个大文件可能要分多次发送)// totalBytesSent 已发送的字节数// totalBytesExpectedToSend 本次上传要发送的总字节数(即一个文件大小)};QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);}
for (int i = 0; i<20; i++) {QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = [NSString stringWithFormat:@"exampleobject-%d",i];// 需要上传的对象内容。可以传入NSData*或者NSURL*类型的变量put.body = [@"My Example Content" dataUsingEncoding:NSUTF8StringEncoding];// 自定义简单上传与分块上传的阈值:默认当文件大于1MB时启用分块上传put.mutilThreshold = 10 *1024*1024;// 监听上传进度[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent 本次要发送的字节数(一个大文件可能要分多次发送)// totalBytesSent 已发送的字节数// totalBytesExpectedToSend 本次上传要发送的总字节数(即一个文件大小)}];// 监听上传结果[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// 在上传结果 result.location 中获取上传文件的下载链接NSString * location = result.location;// 获取文件crc64NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];}
for i in 1...10 {let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = "exampleobject-".appendingFormat("%d", i);// 需要上传的对象内容let dataBody:NSData = "wrwrwrwrwrw".data(using: .utf8)! as NSData;put.body = dataBody;// 自定义简单上传与分块上传的阈值:默认当文件大于1MB时启用分块上传put.mutilThreshold = 10 *1024*1024;// 监听上传结果put.setFinish { (result, error) in// 获取上传结果if let result = result {// 文件的 etaglet eTag = result.eTag// 文件下载链接let location = result.location;// 获取文件crc64let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// 监听上传进度put.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent 本次要发送的字节数(一个大文件可能要分多次发送)// totalBytesSent 已发送的字节数// totalBytesExpectedToSend 本次上传要发送的总字节数(即一个文件大小)};QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);}
for (int i = 0; i<20; i++) {QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = [NSString stringWithFormat:@"exampleobject-%d",i];// 需要上传的对象内容。可以传入NSData*或者NSURL*类型的变量put.body = [@"My Example Content" dataUsingEncoding:NSUTF8StringEncoding];// 自定义分片大小,默认为1MBput.sliceSize = 10 *1024*1024;// 监听上传进度[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent 本次要发送的字节数(一个大文件可能要分多次发送)// totalBytesSent 已发送的字节数// totalBytesExpectedToSend 本次上传要发送的总字节数(即一个文件大小)}];// 监听上传结果[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// 在上传结果 result.location 中获取上传文件的下载链接NSString * location = result.location;// 获取文件crc64NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];}
for i in 1...10 {let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = "exampleobject-".appendingFormat("%d", i);// 需要上传的对象内容let dataBody:NSData = "wrwrwrwrwrw".data(using: .utf8)! as NSData;put.body = dataBody;// 自定义分片大小,默认为1MBput.sliceSize = 10 *1024*1024// 监听上传结果put.setFinish { (result, error) in// 获取上传结果if let result = result {// 文件的 etaglet eTag = result.eTag// 文件下载链接let location = result.location;// 获取文件crc64let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// 监听上传进度put.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent 本次要发送的字节数(一个大文件可能要分多次发送)// totalBytesSent 已发送的字节数// totalBytesExpectedToSend 本次上传要发送的总字节数(即一个文件大小)};QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);}
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = [NSString stringWithFormat:@"exampleobject-%d",i];// 需要上传的对象内容。可以传入NSData*或者NSURL*类型的变量put.body = [@"My Example Content" dataUsingEncoding:NSUTF8StringEncoding];// 使用trafficLimit参数设置上传限速,单位为bit/s,限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s。put.trafficLimit = 819200;// 监听上传进度[put setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// bytesSent 本次要发送的字节数(一个大文件可能要分多次发送)// totalBytesSent 已发送的字节数// totalBytesExpectedToSend 本次上传要发送的总字节数(即一个文件大小)}];// 监听上传结果[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// 在上传结果 result.location 中获取上传文件的下载链接NSString * location = result.location;// 获取文件crc64NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = "exampleobject-".appendingFormat("%d", i);// 需要上传的对象内容let dataBody:NSData = "wrwrwrwrwrw".data(using: .utf8)! as NSData;put.body = dataBody;// 使用trafficLimit参数设置上传限速,单位为bit/s,限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s。put.trafficLimit = 819200;// 监听上传结果put.setFinish { (result, error) in// 获取上传结果if let result = result {// 文件的 etaglet eTag = result.eTag// 文件下载链接let location = result.location;// 获取文件crc64let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}// 监听上传进度put.sendProcessBlock = { (bytesSent, totalBytesSent,totalBytesExpectedToSend) in// bytesSent 本次要发送的字节数(一个大文件可能要分多次发送)// totalBytesSent 已发送的字节数// totalBytesExpectedToSend 本次上传要发送的总字节数(即一个文件大小)};QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);
QCloudCOSXMLUploadObjectRequest* put = [QCloudCOSXMLUploadObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// 要创建的目录的名称put.object = @"dir1";// 需要上传的对象内容,如需创建目录使用空串生成NSData即可put.body = [@"" dataUsingEncoding:NSUTF8StringEncoding];// 监听上传结果[put setFinishBlock:^(QCloudUploadObjectResult *result, NSError *error) {// 在上传结果 result.location 中获取上传文件的下载链接NSString * location = result.location;}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] UploadObject:put];
let put:QCloudCOSXMLUploadObjectRequest = QCloudCOSXMLUploadObjectRequest<AnyObject>();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = "dir/";// 需要上传的对象内容let dataBody:NSData = "".data(using: .utf8)! as NSData;put.body = dataBody;// 监听上传结果put.setFinish { (result, error) in// 获取上传结果if let result = result {// 文件下载链接let location = result.location;} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().uploadObject(put);
/
结尾,否则会被识别为文件夹。QCloudPutObjectRequest* put = [QCloudPutObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketput.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"put.object = @"exampleobject";// 文件内容,可以传入NSData*或者NSURL*类型的变量put.body = [@"testFileContent" dataUsingEncoding:NSUTF8StringEncoding];[put setFinishBlock:^(id result, NSError *error) {// result 包含响应的 header 信息// 获取文件crc64NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSXMLService defaultCOSXML] PutObject:put];
let putObject = QCloudPutObjectRequest<AnyObject>.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketputObject.bucket = "examplebucket-1250000000";// 需要上传的对象内容。可以传入NSData*或者NSURL*类型的变量let dataBody:NSData? = "wrwrwrwrwrw".data(using: .utf8) as NSData?;putObject.body = dataBody!;// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"putObject.object = "exampleobject";putObject.finishBlock = {(result,error) inif let result = result {// 获取文件crc64let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().putObject(putObject);
QCloudListBucketMultipartUploadsRequest* uploads = [QCloudListBucketMultipartUploadsRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketuploads.bucket = @"examplebucket-1250000000";// 设置最大返回的 multipart 数量,合法取值从 1 到 1000uploads.maxUploads = 100;[uploads setFinishBlock:^(QCloudListMultipartUploadsResult* result,NSError *error) {// 可以从 result 中返回分块信息// 进行中的分块上传对象NSArray<QCloudListMultipartUploadContent*> *uploads = result.uploads;}];[[QCloudCOSXMLService defaultCOSXML] ListBucketMultipartUploads:uploads];
let listParts = QCloudListBucketMultipartUploadsRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketlistParts.bucket = "examplebucket-1250000000";// 设置最大返回的 multipart 数量,合法取值从 1 到 1000listParts.maxUploads = 100;listParts.setFinish { (result, error) inif let result = result {// 未完成的所有分块上传任务let uploads = result.uploads;} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().listBucketMultipartUploads(listParts);
QCloudInitiateMultipartUploadRequest* initRequest = [QCloudInitiateMultipartUploadRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketinitRequest.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"initRequest.object = @"exampleobject";// 将作为对象的元数据返回initRequest.cacheControl = @"cacheControl";initRequest.contentDisposition = @"contentDisposition";// 定义 Object 的 ACL 属性。有效值:private,public-read-write,public-read;默认值:privateinitRequest.accessControlList = @"public";// 赋予被授权者读的权限。initRequest.grantRead = @"grantRead";// 赋予被授权者全部权限initRequest.grantFullControl = @"grantFullControl";[initRequest setFinishBlock:^(QCloudInitiateMultipartUploadResult* outputObject,NSError *error) {// 获取分块上传的 uploadId,后续的上传都需要这个 ID,请保存以备后续使用self->uploadId = outputObject.uploadId;}];[[QCloudCOSXMLService defaultCOSXML] InitiateMultipartUpload:initRequest];
let initRequest = QCloudInitiateMultipartUploadRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketinitRequest.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"initRequest.object = "exampleobject";initRequest.setFinish { (result, error) inif let result = result {// 获取分块上传的 uploadId,后续的上传都需要这个 ID,请保存以备后续使用self.uploadId = result.uploadId;} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().initiateMultipartUpload(initRequest);
QCloudUploadPartRequest* request = [QCloudUploadPartRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = @"exampleobject";// 块编号request.partNumber = 1;// 标识本次分块上传的 ID;使用 Initiate Multipart Upload 接口初始化分块上传时会得到一个 uploadIdrequest.uploadId = uploadId;// 上传的数据:支持 NSData*,NSURL(本地 URL) 和 QCloudFileOffsetBody * 三种类型request.body = [@"testFileContent" dataUsingEncoding:NSUTF8StringEncoding];[request setSendProcessBlock:^(int64_t bytesSent,int64_t totalBytesSent,int64_t totalBytesExpectedToSend) {// 上传进度信息// bytesSent 新增字节数// totalBytesSent 本次上传的总字节数// totalBytesExpectedToSend 本地上传的目标字节数}];[request setFinishBlock:^(QCloudUploadPartResult* outputObject, NSError *error) {QCloudMultipartInfo *part = [QCloudMultipartInfo new];// 获取所上传分块的 etagpart.eTag = outputObject.eTag;part.partNumber = @"1";// 保存起来用于最好完成上传时使用self.parts = @[part];// 获取文件crc64NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSXMLService defaultCOSXML] UploadPart:request];
let uploadPart = QCloudUploadPartRequest<AnyObject>.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketuploadPart.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"uploadPart.object = "exampleobject";uploadPart.partNumber = 1;// 标识本次分块上传的 IDif let uploadId = self.uploadId {uploadPart.uploadId = uploadId;}// 示例文件内容let dataBody:NSData? = "wrwrwrwrwrwwrwrwrwrwrwwwrwrw".data(using: .utf8) as NSData?;uploadPart.body = dataBody!;uploadPart.setFinish { (result, error) inif let result = result {let mutipartInfo = QCloudMultipartInfo.init();// 获取分块的 etagmutipartInfo.eTag = result.eTag;mutipartInfo.partNumber = "1";// 保存起来用于最后完成上传时使用self.parts = [mutipartInfo];// 获取文件crc64let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}uploadPart.sendProcessBlock = {(bytesSent,totalBytesSent,totalBytesExpectedToSend) in// 上传进度信息// bytesSent 新增字节数// totalBytesSent 本次上传的总字节数// totalBytesExpectedToSend 本地上传的目标字节数}QCloudCOSXMLService.defaultCOSXML().uploadPart(uploadPart);
QCloudListMultipartRequest* request = [QCloudListMultipartRequest new];// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = @"exampleobject";// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// 在初始化分块上传的响应中,会返回一个唯一的描述符(upload ID)request.uploadId = uploadId;[request setFinishBlock:^(QCloudListPartsResult * _Nonnull result,NSError * _Nonnull error) {// 从 result 中获取已上传分块信息// 用来表示每一个块的信息NSArray<QCloudMultipartUploadPart*> *parts = result.parts;}];[[QCloudCOSXMLService defaultCOSXML] ListMultipart:request];
let req = QCloudListMultipartRequest.init();// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"req.object = "exampleobject";// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketreq.bucket = "examplebucket-1250000000";// 在初始化分块上传的响应中,会返回一个唯一的描述符(upload ID)if let uploadId = self.uploadId {req.uploadId = uploadId;}req.setFinish { (result, error) inif let result = result {// 所有已完成的分片let parts = result.parts} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().listMultipart(req);
QCloudCompleteMultipartUploadRequest *completeRequst = [QCloudCompleteMultipartUploadRequest new];// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"completeRequst.object = @"exampleobject";// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketcompleteRequst.bucket = @"examplebucket-1250000000";// 本次要查询的分块上传的 uploadId,可从初始化分块上传的请求结果 QCloudInitiateMultipartUploadResult 中得到completeRequst.uploadId = uploadId;// 已上传分块的信息QCloudCompleteMultipartUploadInfo *partInfo = [QCloudCompleteMultipartUploadInfo new];NSMutableArray * parts = [self.parts mutableCopy];// 对已上传的块进行排序[parts sortUsingComparator:^NSComparisonResult(QCloudMultipartInfo* _Nonnull obj1,QCloudMultipartInfo* _Nonnull obj2) {int a = obj1.partNumber.intValue;int b = obj2.partNumber.intValue;if (a < b) {return NSOrderedAscending;} else {return NSOrderedDescending;}}];partInfo.parts = [parts copy];completeRequst.parts = partInfo;[completeRequst setFinishBlock:^(QCloudUploadObjectResult * _Nonnull result,NSError * _Nonnull error) {// 从 result 中获取上传结果// 获取文件crc64NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[[QCloudCOSXMLService defaultCOSXML] CompleteMultipartUpload:completeRequst];
let complete = QCloudCompleteMultipartUploadRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketcomplete.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"complete.object = "exampleobject";// 本次要查询的分块上传的 uploadId,可从初始化分块上传的请求结果// QCloudInitiateMultipartUploadResult 中得到complete.uploadId = "exampleUploadId";if let uploadId = self.uploadId {complete.uploadId = uploadId;}// 已上传分块的信息let completeInfo = QCloudCompleteMultipartUploadInfo.init();if self.parts == nil {print("没有要完成的分块");return;}if self.parts != nil {completeInfo.parts = self.parts ?? [];}complete.parts = completeInfo;complete.setFinish { (result, error) inif let result = result {// 文件的 eTaglet eTag = result.eTag// 不带签名的文件链接let location = result.location// 获取文件crc64let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().completeMultipartUpload(complete);
QCloudAbortMultipfartUploadRequest *abortRequest = [QCloudAbortMultipfartUploadRequest new];// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"abortRequest.object = @"exampleobject";// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketabortRequest.bucket = @"examplebucket-1250000000";// 本次要终止的分块上传的 uploadId// 可从初始化分块上传的请求结果 QCloudInitiateMultipartUploadResult 中得到abortRequest.uploadId = @"exampleUploadId";[abortRequest setFinishBlock:^(id outputObject, NSError *error) {// 可以从 outputObject 中获取 response 中 etag 或者自定义头部等信息NSDictionary * result = (NSDictionary *)outputObject;}];[[QCloudCOSXMLService defaultCOSXML]AbortMultipfartUpload:abortRequest];
let abort = QCloudAbortMultipfartUploadRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketabort.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"abort.object = "exampleobject";// 本次要查询的分块上传的 uploadId,可从初始化分块上传的请求结果// QCloudInitiateMultipartUploadResult 中得到abort.uploadId = self.uploadId!;abort.finishBlock = {(result,error)inif let result = result {// 可以从 result 中获取服务器返回的 header 信息} else {print(error!)}}QCloudCOSXMLService.defaultCOSXML().abortMultipfartUpload(abort);
本页内容是否解决了您的问题?