API | 操作名 | 操作描述 |
下载对象 | 下载一个对象至本地 |
QCloudCOSXMLDownloadObjectRequest * request = [QCloudCOSXMLDownloadObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = @"exampleobject";// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = [NSURL fileURLWithPath:@"Local File Path"];// 本地已下载的文件大小,如果是从头开始下载,请不要设置request.localCacheDownloadOffset = 100;// 监听下载结果[request setFinishBlock:^(id outputObject, NSError *error) {// outputObject 包含所有的响应 http 头部NSDictionary* info = (NSDictionary *) outputObject;}];// 监听下载进度[request setDownProcessBlock:^(int64_t bytesDownload,int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// bytesDownload 新增字节数// totalBytesDownload 本次下载接收的总字节数// totalBytesExpectedToDownload 本次下载的目标字节数}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] DownloadObject:request];
let request : QCloudCOSXMLDownloadObjectRequest = QCloudCOSXMLDownloadObjectRequest();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = "exampleobject";// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = NSURL.fileURL(withPath: "Local File Path") as URL?;// 本地已下载的文件大小,如果是从头开始下载,请不要设置request.localCacheDownloadOffset = 100;// 监听下载进度request.sendProcessBlock = { (bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload 新增字节数// totalBytesDownload 本次下载接收的总字节数// totalBytesExpectedToDownload 本次下载的目标字节数}// 监听下载结果request.finishBlock = { (result, error) inif let result = result {// result 包含响应的 header 信息} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().downloadObject(request);
[request cancel];
// 本地已下载的文件大小int64_t localCacheDownloadOffset = 0;request.localCacheDownloadOffset = localCacheDownloadOffset;
[request cancel];
request.cancel();
// 本地已下载的文件大小let localCacheDownloadOffset = 100;request.localCacheDownloadOffset = Int64(localCacheDownloadOffset);
request.cancel();
QCloudCOSXMLDownloadObjectRequest *getObjectRequest = [[QCloudCOSXMLDownloadObjectRequest alloc] init];//支持断点下载,默认不支持getObjectRequest.resumableDownload = true;// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketgetObjectRequest.bucket = transferTestBucket.name;// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中getObjectRequest.downloadingURL = [NSURL URLWithString:QCloudTempFilePathWithExtension(@"downding")];// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"getObjectRequest.object = put.object;// 监听下载结果[getObjectRequest setFinishBlock:^(id outputObject, NSError *error) {// outputObject 包含所有的响应 http 头部NSDictionary* info = (NSDictionary *) outputObject;}];// 监听下载进度[getObjectRequest setDownProcessBlock:^(int64_t bytesDownload,int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// bytesDownload 新增字节数// totalBytesDownload 本次下载接收的总字节数// totalBytesExpectedToDownload 本次下载的目标字节数}];[[QCloudCOSTransferMangerService costransfermangerServiceForKey:kHTTPServiceKey] DownloadObject:getObjectRequest];
let request : QCloudCOSXMLDownloadObjectRequest = QCloudCOSXMLDownloadObjectRequest();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = "exampleobject";request.resumableDownload = true;// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = NSURL.fileURL(withPath: "Local File Path") as URL?;// 本地已下载的文件大小,如果是从头开始下载,请不要设置request.localCacheDownloadOffset = 100;// 监听下载进度request.sendProcessBlock = { (bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload 新增字节数// totalBytesDownload 本次下载接收的总字节数// totalBytesExpectedToDownload 本次下载的目标字节数}// 监听下载结果request.finishBlock = { (result, error) inif let result = result {// result 包含响应的 header 信息} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().downloadObject(request);}
for (int i = 0; i<20; i++) {QCloudCOSXMLDownloadObjectRequest * request = [QCloudCOSXMLDownloadObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = @"exampleobject";// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = [NSURL fileURLWithPath:@"Local File Path"];// 本地已下载的文件大小,如果是从头开始下载,请不要设置request.localCacheDownloadOffset = 100;// 监听下载结果[request setFinishBlock:^(id outputObject, NSError *error) {// outputObject 包含所有的响应 http 头部NSDictionary* info = (NSDictionary *) outputObject;}];// 监听下载进度[request setDownProcessBlock:^(int64_t bytesDownload,int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// bytesDownload 新增字节数// totalBytesDownload 本次下载接收的总字节数// totalBytesExpectedToDownload 本次下载的目标字节数}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] DownloadObject:request];}
for i in 1...10 {let request : QCloudCOSXMLDownloadObjectRequest = QCloudCOSXMLDownloadObjectRequest();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = "exampleobject";// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = NSURL.fileURL(withPath: "Local File Path") as URL?;// 本地已下载的文件大小,如果是从头开始下载,请不要设置request.localCacheDownloadOffset = 100;// 监听下载进度request.sendProcessBlock = { (bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload 新增字节数// totalBytesDownload 本次下载接收的总字节数// totalBytesExpectedToDownload 本次下载的目标字节数}// 监听下载结果request.finishBlock = { (result, error) inif let result = result {// result 包含响应的 header 信息} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().downloadObject(request);}
QCloudGetBucketRequest* request = [QCloudGetBucketRequest new];// 存储桶名称,格式为 BucketName-APPIDrequest.bucket = @"examplebucket-1250000000";// 单次返回的最大条目数量,默认1000request.maxKeys = 100;//要下载的文件夹在cos上的完整路径request.prefix = @"cos_path";[request setFinishBlock:^(QCloudListBucketResult * result, NSError* error) {if(!error){for (QCloudBucketContents *content in result.contents) {QCloudCOSXMLDownloadObjectRequest * request = [QCloudCOSXMLDownloadObjectRequest new];// 存储桶名称,格式为 BucketName-APPIDrequest.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "dir1/object1"request.object = content.key;// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = [NSURL fileURLWithPath:[@"Local File Path" stringByAppendingFormat:@"/%@",content.key]];// 监听下载结果[request setFinishBlock:^(id outputObject, NSError *error) {// outputObject 包含所有的响应 http 头部NSDictionary* info = (NSDictionary *) outputObject;}];// 监听下载进度[request setDownProcessBlock:^(int64_t bytesDownload,int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// bytesDownload 新增字节数// totalBytesDownload 本次下载接收的总字节数// totalBytesExpectedToDownload 本次下载的目标字节数}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] DownloadObject:request];}}}];[[QCloudCOSXMLService defaultCOSXML] GetBucket:request];
let getBucketReq = QCloudGetBucketRequest.init();// 存储桶名称,格式为 BucketName-APPIDgetBucketReq.bucket = "examplebucket-1250000000";// 单次返回的最大条目数量,默认1000getBucketReq.maxKeys = 100;//要下载的文件夹在cos上的完整路径getBucketReq.prefix = "cos_path";getBucketReq.setFinish { (result, error) inif let result = result {let contents = result.contents;for content in contents {let info = QCloudDeleteObjectInfo.init();let request : QCloudCOSXMLDownloadObjectRequest = QCloudCOSXMLDownloadObjectRequest();// 存储桶名称,格式为 BucketName-APPIDrequest.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "dir1/object1"request.object = content.key;// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = NSURL.fileURL(withPath: "Local File Path" ) as URL?;// 本地已下载的文件大小,如果是从头开始下载,请不要设置request.localCacheDownloadOffset = 100;// 监听下载进度request.sendProcessBlock = { (bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload 新增字节数// totalBytesDownload 本次下载接收的总字节数// totalBytesExpectedToDownload 本次下载的目标字节数}// 监听下载结果request.finishBlock = { (result, error) inif let result = result {// result 包含响应的 header 信息} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().downloadObject(request);}} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().getBucket(getBucketReq);
QCloudCOSXMLDownloadObjectRequest * request = [QCloudCOSXMLDownloadObjectRequest new];// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = @"exampleobject";// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = [NSURL fileURLWithPath:@"Local File Path"];// 本地已下载的文件大小,如果是从头开始下载,请不要设置request.localCacheDownloadOffset = 100;// 使用trafficLimit参数设置下载限速,单位为bit/s,限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s。request.trafficLimit = 819200;// 监听下载结果[request setFinishBlock:^(id outputObject, NSError *error) {// outputObject 包含所有的响应 http 头部NSDictionary* info = (NSDictionary *) outputObject;}];// 监听下载进度[request setDownProcessBlock:^(int64_t bytesDownload,int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// bytesDownload 新增字节数// totalBytesDownload 本次下载接收的总字节数// totalBytesExpectedToDownload 本次下载的目标字节数}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] DownloadObject:request];
let request : QCloudCOSXMLDownloadObjectRequest = QCloudCOSXMLDownloadObjectRequest();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = "exampleobject";// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = NSURL.fileURL(withPath: "Local File Path") as URL?;// 本地已下载的文件大小,如果是从头开始下载,请不要设置request.localCacheDownloadOffset = 100;// 使用trafficLimit参数设置下载限速,单位为bit/s,限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s。request.trafficLimit = 819200;// 监听下载进度request.sendProcessBlock = { (bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload 新增字节数// totalBytesDownload 本次下载接收的总字节数// totalBytesExpectedToDownload 本次下载的目标字节数}// 监听下载结果request.finishBlock = { (result, error) inif let result = result {// result 包含响应的 header 信息} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().downloadObject(request);
QCloudGetObjectRequest* request = [QCloudGetObjectRequest new];// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = [NSURL URLWithString:QCloudTempFilePathWithExtension(@"downding")];// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = @"exampleobject";// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";[request setFinishBlock:^(id outputObject, NSError *error) {// 可以从 outputObject 中获取 response 中 etag 或者自定义头部等信息NSDictionary* info = (NSDictionary *) outputObject;// 服务端文件的crc64result[@"x-cos-hash-crc64ecma"]// 下载到本地的文件crc64 若返回的crc64与本地计算一致,则表示下载的文件与远端文件完整一致;uint64_t localCrc64 = [本地文件data qcloud_crc64];}];[request setDownProcessBlock:^(int64_t bytesDownload, int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// 下载过程中的进度// bytesDownload 一次下载的字节数,// totalBytesDownload 总过接受的字节数// totalBytesExpectedToDownload 文件一共多少字节}];[[QCloudCOSXMLService defaultCOSXML] GetObject:request];
let getObject = QCloudGetObjectRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketgetObject.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"getObject.object = "exampleobject";// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中getObject.downloadingURL = URL.init(string: NSTemporaryDirectory())!.appendingPathComponent(getObject.object);getObject.finishBlock = {(result,error) inif let result = result {// 服务端文件的crc64result["x-cos-hash-crc64ecma"]// 下载到本地的文件crc64 若返回的crc64与本地计算一致,则表示下载的文件与远端文件完整一致;uint64_t localCrc64 = 本地文件data.qcloud_crc64();} else {print(error!);}};getObject.downProcessBlock = {(bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload 一次下载的字节数,// totalBytesDownload 总过接受的字节数// totalBytesExpectedToDownload 文件一共多少字节}QCloudCOSXMLService.defaultCOSXML().getObject(getObject);
QCloudGetObjectRequest* request = [QCloudGetObjectRequest new];// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中request.downloadingURL = [NSURL URLWithString:QCloudTempFilePathWithExtension(@"downding")];// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"request.object = @"exampleobject";// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// 使用trafficLimit参数设置下载限速,单位为bit/s,限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s。request.trafficLimit = 819200;[request setFinishBlock:^(id outputObject, NSError *error) {// 可以从 outputObject 中获取 response 中 etag 或者自定义头部等信息NSDictionary* info = (NSDictionary *) outputObject;// 获取文件crc64NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[request setDownProcessBlock:^(int64_t bytesDownload, int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// 下载过程中的进度// bytesDownload 一次下载的字节数,// totalBytesDownload 总过接受的字节数// totalBytesExpectedToDownload 文件一共多少字节}];[[QCloudCOSXMLService defaultCOSXML] GetObject:request];
let getObject = QCloudGetObjectRequest.init();// 存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.tencentcloud.com/cos5/bucketgetObject.bucket = "examplebucket-1250000000";// 对象键,是对象在 COS 上的完整路径,如果带目录的话,格式为 "video/xxx/movie.mp4"getObject.object = "exampleobject";// 设置下载的路径 URL,如果设置了,文件将会被下载到指定路径中getObject.downloadingURL = URL.init(string: NSTemporaryDirectory())!.appendingPathComponent(getObject.object);// 使用trafficLimit参数设置下载限速,单位为bit/s,限速值设置范围为819200 - 838860800,即100KB/s - 100MB/s。getObject.trafficLimit = 819200;getObject.finishBlock = {(result,error) inif let result = result {// result 包含响应的 header 信息// 获取文件crc64let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}};getObject.downProcessBlock = {(bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload 一次下载的字节数,// totalBytesDownload 总过接受的字节数// totalBytesExpectedToDownload 文件一共多少字节}QCloudCOSXMLService.defaultCOSXML().getObject(getObject);
本页内容是否解决了您的问题?