API | Operation | Description |
Downloading an object | Downloads an object to the local file system. |
QCloudCOSXMLDownloadObjectRequest * request = [QCloudCOSXMLDownloadObjectRequest new];// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = [NSURL fileURLWithPath:@"Local File Path"];// The size of the part of the file that has already been downloaded. Do not set this value for a new download operationrequest.localCacheDownloadOffset = 100;// Monitor the download result[request setFinishBlock:^(id outputObject, NSError *error) {// `outputObject` contains all the HTTP response headersNSDictionary* info = (NSDictionary *) outputObject;}];// Monitor the download progress[request setDownProcessBlock:^(int64_t bytesDownload,int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// bytesDownload Number of new bytes downloaded// totalBytesDownload Total number of bytes received in the download// totalBytesExpectedToDownload Target number of bytes expected to be downloaded}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] DownloadObject:request];
let request : QCloudCOSXMLDownloadObjectRequest = QCloudCOSXMLDownloadObjectRequest();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = "exampleobject";// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = NSURL.fileURL(withPath: "Local File Path") as URL?;// The size of the part of the file that has already been downloaded. Do not set this value for a new download operationrequest.localCacheDownloadOffset = 100;// Monitor the download progressrequest.sendProcessBlock = { (bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload Number of new bytes downloaded// totalBytesDownload Total number of bytes received in the download// totalBytesExpectedToDownload Target number of bytes expected to be downloaded}// Monitor the download resultrequest.finishBlock = { (result, error) inif let result = result {// "result" contains response headers.} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().downloadObject(request);
[request cancel];
// Size of the downloaded part of the fileint64_t localCacheDownloadOffset = 0;request.localCacheDownloadOffset = localCacheDownloadOffset;
[request cancel];
request.cancel();
// Size of the downloaded part of the filelet localCacheDownloadOffset = 100;request.localCacheDownloadOffset = Int64(localCacheDownloadOffset);
request.cancel();
QCloudCOSXMLDownloadObjectRequest *getObjectRequest = [[QCloudCOSXMLDownloadObjectRequest alloc] init];// Enable resumable download. Resumable download is disabled by defaultgetObjectRequest.resumableDownload = true;// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketgetObjectRequest.bucket = transferTestBucket.name;// Set the download URL. Once set, the file will be downloaded to the specified pathgetObjectRequest.downloadingURL = [NSURL URLWithString:QCloudTempFilePathWithExtension(@"downding")];// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"getObjectRequest.object = put.object;// Monitor the download result[getObjectRequest setFinishBlock:^(id outputObject, NSError *error) {// `outputObject` contains all the HTTP response headersNSDictionary* info = (NSDictionary *) outputObject;}];// Monitor the download progress[getObjectRequest setDownProcessBlock:^(int64_t bytesDownload,int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// bytesDownload Number of new bytes downloaded// totalBytesDownload Total number of bytes received in the download// totalBytesExpectedToDownload Target number of bytes expected to be downloaded}];[[QCloudCOSTransferMangerService costransfermangerServiceForKey:kHTTPServiceKey] DownloadObject:getObjectRequest];
let request : QCloudCOSXMLDownloadObjectRequest = QCloudCOSXMLDownloadObjectRequest();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = "exampleobject";request.resumableDownload = true;// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = NSURL.fileURL(withPath: "Local File Path") as URL?;// The size of the part of the file that has already been downloaded. Do not set this value for a new download operationrequest.localCacheDownloadOffset = 100;// Monitor the download progressrequest.sendProcessBlock = { (bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload Number of new bytes downloaded// totalBytesDownload Total number of bytes received in the download// totalBytesExpectedToDownload Target number of bytes expected to be downloaded}// Monitor the download resultrequest.finishBlock = { (result, error) inif let result = result {// "result" contains response headers.} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().downloadObject(request);}
for (int i = 0; i<20; i++) {QCloudCOSXMLDownloadObjectRequest * request = [QCloudCOSXMLDownloadObjectRequest new];// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = [NSURL fileURLWithPath:@"Local File Path"];// The size of the part of the file that has already been downloaded. Do not set this value for a new download operationrequest.localCacheDownloadOffset = 100;// Monitor the download result[request setFinishBlock:^(id outputObject, NSError *error) {// `outputObject` contains all the HTTP response headersNSDictionary* info = (NSDictionary *) outputObject;}];// Monitor the download progress[request setDownProcessBlock:^(int64_t bytesDownload,int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// bytesDownload Number of new bytes downloaded// totalBytesDownload Total number of bytes received in the download// totalBytesExpectedToDownload Target number of bytes expected to be downloaded}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] DownloadObject:request];}
for i in 1...10 {let request : QCloudCOSXMLDownloadObjectRequest = QCloudCOSXMLDownloadObjectRequest();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = "exampleobject";// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = NSURL.fileURL(withPath: "Local File Path") as URL?;// The size of the part of the file that has already been downloaded. Do not set this value for a new download operationrequest.localCacheDownloadOffset = 100;// Monitor the download progressrequest.sendProcessBlock = { (bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload Number of new bytes downloaded// totalBytesDownload Total number of bytes received in the download// totalBytesExpectedToDownload Target number of bytes expected to be downloaded}// Monitor the download resultrequest.finishBlock = { (result, error) inif let result = result {// "result" contains response headers.} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().downloadObject(request);}
QCloudGetBucketRequest* request = [QCloudGetBucketRequest new];// Bucket name in the format: `BucketName-APPID`request.bucket = @"examplebucket-1250000000";// Maximum number of objects to return at a time. Default value: 1000request.maxKeys = 100;// The full path of a COS folder to be downloadedrequest.prefix = @"cos_path";[request setFinishBlock:^(QCloudListBucketResult * result, NSError* error) {if(!error){for (QCloudBucketContents *content in result.contents) {QCloudCOSXMLDownloadObjectRequest * request = [QCloudCOSXMLDownloadObjectRequest new];// Bucket name in the format: `BucketName-APPID`request.bucket = @"examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".request.object = content.key;// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = [NSURL fileURLWithPath:[@"Local File Path" stringByAppendingFormat:@"/%@",content.key]];// Monitor the download result[request setFinishBlock:^(id outputObject, NSError *error) {// `outputObject` contains all the HTTP response headersNSDictionary* info = (NSDictionary *) outputObject;}];// Monitor the download progress[request setDownProcessBlock:^(int64_t bytesDownload,int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// bytesDownload Number of new bytes downloaded// totalBytesDownload Total number of bytes received in the download// totalBytesExpectedToDownload Target number of bytes expected to be downloaded}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] DownloadObject:request];}}}];[[QCloudCOSXMLService defaultCOSXML] GetBucket:request];
let getBucketReq = QCloudGetBucketRequest.init();// Bucket name in the format: `BucketName-APPID`getBucketReq.bucket = "examplebucket-1250000000";// Maximum number of objects to return at a time. Default value: 1000getBucketReq.maxKeys = 100;// The full path of a COS folder to be downloadedgetBucketReq.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();// Bucket name in the format: `BucketName-APPID`request.bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".request.object = content.key;// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = NSURL.fileURL(withPath: "Local File Path" ) as URL?;// The size of the part of the file that has already been downloaded. Do not set this value for a new download operationrequest.localCacheDownloadOffset = 100;// Monitor the download progressrequest.sendProcessBlock = { (bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload Number of new bytes downloaded// totalBytesDownload Total number of bytes received in the download// totalBytesExpectedToDownload Target number of bytes expected to be downloaded}// Monitor the download resultrequest.finishBlock = { (result, error) inif let result = result {// "result" contains response headers.} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().downloadObject(request);}} else {print(error!);}}QCloudCOSXMLService.defaultCOSXML().getBucket(getBucketReq);
QCloudCOSXMLDownloadObjectRequest * request = [QCloudCOSXMLDownloadObjectRequest new];// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = [NSURL fileURLWithPath:@"Local File Path"];// The size of the part of the file that has already been downloaded. Do not set this value for a new download operationrequest.localCacheDownloadOffset = 100;// Use `TrafficLimit` to limit the download speed, in bit/s. The speed range is 819200 to 838860800, that is, 100 KB/s to 100 MB/s.request.trafficLimit = 819200;// Monitor the download result[request setFinishBlock:^(id outputObject, NSError *error) {// `outputObject` contains all the HTTP response headersNSDictionary* info = (NSDictionary *) outputObject;}];// Monitor the download progress[request setDownProcessBlock:^(int64_t bytesDownload,int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// bytesDownload Number of new bytes downloaded// totalBytesDownload Total number of bytes received in the download// totalBytesExpectedToDownload Target number of bytes expected to be downloaded}];[[QCloudCOSTransferMangerService defaultCOSTransferManager] DownloadObject:request];
let request : QCloudCOSXMLDownloadObjectRequest = QCloudCOSXMLDownloadObjectRequest();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = "examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = "exampleobject";// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = NSURL.fileURL(withPath: "Local File Path") as URL?;// The size of the part of the file that has already been downloaded. Do not set this value for a new download operationrequest.localCacheDownloadOffset = 100;// Use `TrafficLimit` to limit the download speed, in bit/s. The speed range is 819200 to 838860800, that is, 100 KB/s to 100 MB/s.request.trafficLimit = 819200;// Monitor the download progressrequest.sendProcessBlock = { (bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload Number of new bytes downloaded// totalBytesDownload Total number of bytes received in the download// totalBytesExpectedToDownload Target number of bytes expected to be downloaded}// Monitor the download resultrequest.finishBlock = { (result, error) inif let result = result {// "result" contains response headers.} else {print(error!);}}QCloudCOSTransferMangerService.defaultCOSTransferManager().downloadObject(request);
QCloudGetObjectRequest* request = [QCloudGetObjectRequest new];// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = [NSURL URLWithString:QCloudTempFilePathWithExtension(@"downding")];// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";[request setFinishBlock:^(id outputObject, NSError *error) {// outputObject contains information such as the ETag or custom headers in the response.NSDictionary* info = (NSDictionary *) outputObject;// The CRC64 value of a server objectresult[@"x-cos-hash-crc64ecma"]// The CRC64 value of a downloaded local object. If the returned CRC64 value is consistent with the local calculation, the downloaded object is the same as the server object.uint64_t localCrc64 = [Local object data qcloud_crc64];}];[request setDownProcessBlock:^(int64_t bytesDownload, int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// Download progress// bytesDownload Number of downloaded bytes// totalBytesDownload Total number of bytes received for the download// totalBytesExpectedToDownload Total number of bytes in the file}];[[QCloudCOSXMLService defaultCOSXML] GetObject:request];
let getObject = QCloudGetObjectRequest.init();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketgetObject.bucket = "examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"getObject.object = "exampleobject";// Set the download URL. Once set, the file will be downloaded to the specified pathgetObject.downloadingURL = URL.init(string: NSTemporaryDirectory())!.appendingPathComponent(getObject.object);getObject.finishBlock = {(result,error) inif let result = result {// The CRC64 value of a server objectresult["x-cos-hash-crc64ecma"]// The CRC64 value of a downloaded local object. If the returned CRC64 value is consistent with the local calculation, the downloaded object is the same as the server object.uint64_t localCrc64 = Local object data.qcloud_crc64();} else {print(error!);}};getObject.downProcessBlock = {(bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload Number of downloaded bytes// totalBytesDownload Total number of bytes received for the download// totalBytesExpectedToDownload Total number of bytes in the file}QCloudCOSXMLService.defaultCOSXML().getObject(getObject);
QCloudGetObjectRequest* request = [QCloudGetObjectRequest new];// Set the download URL. Once set, the file will be downloaded to the specified pathrequest.downloadingURL = [NSURL URLWithString:QCloudTempFilePathWithExtension(@"downding")];// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"request.object = @"exampleobject";// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketrequest.bucket = @"examplebucket-1250000000";// Use `TrafficLimit` to limit the download speed, in bit/s. The speed range is 819200 to 838860800, that is, 100 KB/s to 100 MB/s.request.trafficLimit = 819200;[request setFinishBlock:^(id outputObject, NSError *error) {// outputObject contains information such as the ETag or custom headers in the response.NSDictionary* info = (NSDictionary *) outputObject;// Obtain the CRC64 value of the object.NSString * crc64 = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-hash-crc64ecma"];}];[request setDownProcessBlock:^(int64_t bytesDownload, int64_t totalBytesDownload,int64_t totalBytesExpectedToDownload) {// Download progress// bytesDownload Number of downloaded bytes// totalBytesDownload Total number of bytes received for the download// totalBytesExpectedToDownload Total number of bytes in the file}];[[QCloudCOSXMLService defaultCOSXML] GetObject:request];
let getObject = QCloudGetObjectRequest.init();// Bucket name in the format of BucketName-Appid, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucketgetObject.bucket = "examplebucket-1250000000";// Object key, i.e. the full path of a COS object. If the object is in a directory, the path should be "video/xxx/movie.mp4"getObject.object = "exampleobject";// Set the download URL. Once set, the file will be downloaded to the specified pathgetObject.downloadingURL = URL.init(string: NSTemporaryDirectory())!.appendingPathComponent(getObject.object);// Use `TrafficLimit` to limit the download speed, in bit/s. The speed range is 819200 to 838860800, that is, 100 KB/s to 100 MB/s.getObject.trafficLimit = 819200;getObject.finishBlock = {(result,error) inif let result = result {// "result" contains response headers.// Obtain the CRC64 value of the object.let crc64 = result?.__originHTTPURLResponse__.allHeaderFields["x-cos-hash-crc64ecma"];} else {print(error!);}};getObject.downProcessBlock = {(bytesDownload, totalBytesDownload,totalBytesExpectedToDownload) in// bytesDownload Number of downloaded bytes// totalBytesDownload Total number of bytes received for the download// totalBytesExpectedToDownload Total number of bytes in the file}QCloudCOSXMLService.defaultCOSXML().getObject(getObject);
Apakah halaman ini membantu?