Release Notes
Announcements
cos:PutObject, and the authorization action for the source object needs to be set to cos:GetObject. For more authorization, see CAM-supported business APIs.cos:InitiateMultipartUpload, cos:PutObject, cos:CompleteMultipartUpload, and the authorization action for the source object needs to be set to cos:GetObject. For more authorization, see CAM-supported business APIs.cos:PutObject, and the authorization actions for the source object need to be set to cos:GetObject and cos:DeleteObject. For more authorization, see CAM-supported business APIs.Function Name | Description | Example code |
Advanced Copy | The Advanced Copy API encapsulates the Simple Copy and Multipart Copy APIs, intelligently selecting the method to copy objects based on file size. | |
Simple Copy | The Simple Copy API can copy an object to a specified bucket and does not support automatic multipart copy. It supports copying objects up to 5GB in size. For objects larger than 5GB, please use the Advanced API to copy. | |
Move Object | The Move Object API encapsulates copy and delete operations. It only supports moving objects within the current bucket. For cross-bucket movement, you can use the Advanced Copy API and Delete Object API to achieve this. |
qcloud_cos::CosAPI InitCosAPI() {uint64_t appid = 12500000000;std::string region = "ap-guangzhou";// Region of the bucket, see https://www.tencentcloud.com/document/product/436/62?from_cn_redirect=1std::string secret_id = "************************************"; // User's SecretId. It is recommended to use sub-account keys, with authorization following the least privilege principle to mitigate usage risks. For information on how to obtain sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1std::string secret_key = "************************************"; // User's SecretKey. It is recommended to use sub-account keys, with authorization following the least privilege principle to mitigate usage risks. For information on how to obtain sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1qcloud_cos::CosConfig config(appid, secret_id, secret_key, region);qcloud_cos::CosAPI cos_tmp(config);return cos_tmp;}
qcloud_cos::CosAPI InitCosAPI() {// You need to have obtained the temporary key results: tmp_secret_id, tmp_secret_key,// For generating temporary keys, see https://www.tencentcloud.com/document/product/436/14048?from_cn_redirect=1#cos-sts-sdkuint64_t appid = 12500000000;std::string region = "ap-guangzhou";std::string tmp_secret_id = "************************************";std::string tmp_secret_key = "************************************";std::string tmp_token = "token";qcloud_cos::CosConfig config(appid, tmp_secret_id, tmp_secret_key, region);config.SetTmpToken(tmp_token);qcloud_cos::CosAPI cos_tmp(config);return cos_tmp;}
CosResult CosAPI::Copy(const CopyReq& req, CopyResp* resp)
void CopyDemo(qcloud_cos::CosAPI& cos) {std::string object_name = "test_dst.txt"; // Object name after copyingstd::string source = bucket_name + ".cos." + region + ".myqcloud.com/test_src.txt"; ; // Source object for copying// The part size for multipart copy is set to 20MB by default, with a maximum supported size of 5GB and a minimum of 1MB// This configuration is global. Once explicitly set, all subsequently initialized CopyReq instances will use this configuration.CosSysConfig::SetUploadCopyPartSize(20 * 1024 * 1024);qcloud_cos::CopyReq req(bucket_name, object_name);// Target bucket name and object nameqcloud_cos::CopyResp resp;req.SetXCosCopySource(source);qcloud_cos::CosResult result = cos.Copy(req, &resp);std::cout << "===========================Copy=============================" << std::endl;PrintResult(result, resp);std::cout << "============================================================" << std::endl;}
Parameter Name | Description | Type |
req | Copy file request | CopyReq |
resp | Copy file response | CopyResp |
Member or Function | Description | Parameter Type |
bucket_name | Target bucket name, which can be set via the constructor or set method. The naming format for buckets is BucketName-APPID. For details, see Naming Conventions | string |
object_name | Target object key (Key), which can be set via the constructor or set method. is the unique identifier of the object in the bucket. For example, in the object access domain name examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/picture.jpg, the object key is doc/picture.jpg. For details, see Object Key | string |
SetXCosCopySource | Used to set the source object location for copying. | string |
Member functions | Description | Return Type |
GetVersionId | Get the version number of the Object. If versioning is not enabled for the Bucket, an empty string is returned. | string |
GetXCosServerSideEncryption | Obtain the server-side encryption algorithm used | string |
GetEtag | Obtain the Etag of the stored object. | string |
GetXCosRequestId | Obtain the request ID. | string |
Member functions | Description | Parameter Type |
SetUploadCopyPartSize | Set the part size for multipart copy, unit: byte (Byte), default: 20MB. The setting method is CosSysConfig::SetUploadCopyPartSize(20 * 1024 * 1024). | uint64_t |
SetUploadThreadPoolSize | Set the download thread pool size, defaulting to 5. The setting method is CosSysConfig::SetUploadThreadPoolSize(5). | unsigned |
Member functions | Description | Return Type |
IsSucc | Indicates whether the operation is successful; returns true for success, false for failure. | bool |
GetHttpStatus | Obtain the http status code. | int |
GetErrorCode | Obtain the error code when the request fails. | string |
GetErrorMsg | Obtain the error message when the request fails. | string |
GetXCosRequestId | Obtain the request ID. | string |
void PrintResult(const qcloud_cos::CosResult& result, const qcloud_cos::BaseResp& resp) {if (result.IsSucc()) {std::cout << "Request Succ." << std::endl;std::cout << resp.DebugString() << std::endl;} else {std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
qcloud_cos::CosAPI InitCosAPI() {uint64_t appid = 12500000000;std::string region = "ap-guangzhou";// Region of the bucket, see https://www.tencentcloud.com/document/product/436/62?from_cn_redirect=1std::string secret_id = "************************************"; // User's SecretId. It is recommended to use sub-account keys, with authorization following the least privilege principle to mitigate usage risks. For information on how to obtain sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1std::string secret_key = "************************************"; // User's SecretKey. It is recommended to use sub-account keys, with authorization following the least privilege principle to mitigate usage risks. For information on how to obtain sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1qcloud_cos::CosConfig config(appid, secret_id, secret_key, region);qcloud_cos::CosAPI cos_tmp(config);return cos_tmp;}
qcloud_cos::CosAPI InitCosAPI() {// You need to have obtained the temporary key results: tmp_secret_id, tmp_secret_key,// For generating temporary keys, see https://www.tencentcloud.com/document/product/436/14048?from_cn_redirect=1#cos-sts-sdkuint64_t appid = 12500000000;std::string region = "ap-guangzhou";std::string tmp_secret_id = "************************************";std::string tmp_secret_key = "************************************";std::string tmp_token = "token";qcloud_cos::CosConfig config(appid, tmp_secret_id, tmp_secret_key, region);config.SetTmpToken(tmp_token);qcloud_cos::CosAPI cos_tmp(config);return cos_tmp;}
CosResult CosAPI::PutObjectCopy(const PutObjectCopyReq& req, PutObjectCopyResp* resp)
void PutObjectCopyDemo(qcloud_cos::CosAPI& cos) {std::string object_name = "test_dst.txt"; // Target object name for copyingstd::string source = bucket_name + ".cos." + region + ".myqcloud.com/test.txt"; // Source object for copyingqcloud_cos::PutObjectCopyReq req(bucket_name, object_name);// Target bucket name and object namereq.SetXCosCopySource(source);qcloud_cos::PutObjectCopyResp resp;qcloud_cos::CosResult result = cos.PutObjectCopy(req, &resp);std::cout << "===================PutObjectCopyResponse====================" << std::endl;PrintResult(result, resp);std::cout << "============================================================" << std::endl;}
Parameter Name | Description | Type |
req | Copy file request | PutObjectCopyReq |
resp | Copy file response | PutObjectCopyResp |
Member or Function | Description | Parameter Type |
bucket_name | Target bucket name, which can be set via the constructor or set method. The naming format for buckets is BucketName-APPID. For details, see Naming Conventions | string |
object_name | Target object key (Key), which can be set via the constructor or set method. is the unique identifier of the object in the bucket. For example, in the object access domain name examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/picture.jpg, the object key is doc/picture.jpg. For details, see Object Key | string |
SetXCosCopySource | Used to set the source object location for copying. | string |
Member functions | Description | Return Type |
GetVersionId | Get the version number of the Object. If versioning is not enabled for the Bucket, an empty string is returned. | string |
GetXCosServerSideEncryption | Obtain the server-side encryption algorithm used | string |
GetEtag | Obtain the Etag of the stored object. | string |
GetXCosRequestId | Obtain the request ID. | string |
Member functions | Description | Return Type |
IsSucc | Indicates whether the operation is successful; returns true for success, false for failure. | bool |
GetHttpStatus | Obtain the http status code. | int |
GetErrorCode | The error code can be obtained when the request fails. | string |
GetErrorMsg | Obtain the error message when the request fails. | string |
GetXCosRequestId | Obtain the request ID. | string |
void PrintResult(const qcloud_cos::CosResult& result, const qcloud_cos::BaseResp& resp) {if (result.IsSucc()) {std::cout << "Request Succ." << std::endl;std::cout << resp.DebugString() << std::endl;} else {std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
qcloud_cos::CosAPI InitCosAPI() {uint64_t appid = 12500000000;std::string region = "ap-guangzhou";// Region of the bucket, see https://www.tencentcloud.com/document/product/436/62?from_cn_redirect=1std::string secret_id = "************************************"; // User's SecretId. It is recommended to use sub-account keys, with authorization following the least privilege principle to mitigate usage risks. For information on how to obtain sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1std::string secret_key = "************************************"; // User's SecretKey. It is recommended to use sub-account keys, with authorization following the least privilege principle to mitigate usage risks. For information on how to obtain sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1qcloud_cos::CosConfig config(appid, secret_id, secret_key, region);qcloud_cos::CosAPI cos_tmp(config);return cos_tmp;}
qcloud_cos::CosAPI InitCosAPI() {// You need to have obtained the temporary key results: tmp_secret_id, tmp_secret_key,// For generating temporary keys, see https://www.tencentcloud.com/document/product/436/14048?from_cn_redirect=1#cos-sts-sdkuint64_t appid = 12500000000;std::string region = "ap-guangzhou";std::string tmp_secret_id = "************************************";std::string tmp_secret_key = "************************************";std::string tmp_token = "token";qcloud_cos::CosConfig config(appid, tmp_secret_id, tmp_secret_key, region);config.SetTmpToken(tmp_token);qcloud_cos::CosAPI cos_tmp(config);return cos_tmp;}
CosResult CosAPI::MoveObject(const MoveObjectReq& req)
void MoveObjectDemo(qcloud_cos::CosAPI& cos) {std::string src_object = "test_src.txt";std::string dst_object = "test_dst.txt";qcloud_cos::MoveObjectReq req(bucket_name, src_object, dst_object);qcloud_cos::CosResult result = cos.MoveObject(req);std::cout << "========================MoveObject==========================" << std::endl;if (result.IsSucc()) {std::cout << "MoveObject Succ." << std::endl;} else {std::cout << "MoveObject Fail, ErrorMsg: " << result.GetErrorMsg() << std::endl;}std::cout << "============================================================" << std::endl;}
Parameter Name | Description | Type |
req | Move Object Request | MoveObjectReq |
Member or Function | Description | Parameter Type |
bucket_name | Target and source bucket names, which can be set via the constructor or set method. The naming format for buckets is BucketName-APPID. For details, see Naming Conventions | string |
src_object | Source object key (Key), which can be set via the constructor or set method. is the unique identifier of the object in the bucket. For example, in the object access domain name examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/picture.jpg, the object key is doc/picture.jpg. For details, see Object Key | string |
dst_object | Target Object Key | string |
Member functions | Description | Return Type |
IsSucc | Indicates whether the operation is successful; returns true for success, false for failure. | bool |
GetHttpStatus | Obtain the http status code. | int |
GetErrorCode | The error code can be obtained when the request fails. | string |
GetErrorMsg | Obtain the error message when the request fails. | string |
GetXCosRequestId | Obtain the request ID. | string |
void PrintResult(const qcloud_cos::CosResult& result, const qcloud_cos::BaseResp& resp) {if (result.IsSucc()) {std::cout << "Request Succ." << std::endl;std::cout << resp.DebugString() << std::endl;} else {std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback