产品动态
产品公告
cos:PutObject ,源对象的授权 action 需要设置为cos:GetObject ,更多授权请参见 支持CAM的业务接口。cos:InitiateMultipartUpload,cos:PutObject,cos:CompleteMultipartUpload,源对象的授权 action 需要设置为cos:GetObject ,更多授权请参见 支持CAM的业务接口。cos:PutObject,源对象的授权 action 需要设置为cos:GetObject和cos:DeleteObject,更多授权请参见 支持CAM的业务接口。功能名称 | 描述 | 示例代码 |
高级拷贝 | 高级复制接口封装了简单拷贝、分块拷贝接口,根据文件大小智能的选择拷贝对象的方式。 | |
简单拷贝 | 简单复制接口可以拷贝一个对象至指定存储桶中,不支持自动分块拷贝。最大支持拷贝不超过5GB的对象,5GB以上对象请使用 高级接口 拷贝。 | |
移动对象 | 移动对象接口封装了拷贝和删除操作。仅支持当前存储桶内移动对象。如需跨桶移动,可以使用高级拷贝接口和删除对象接口实现。 |
qcloud_cos::CosAPI InitCosAPI() {uint64_t appid = 12500000000;std::string region = "ap-guangzhou";// bucket 的地域,请参见 https://www.tencentcloud.com/document/product/436/62?from_cn_redirect=1std::string secret_id = "************************************"; //用户的 SecretId,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1std::string secret_key = "************************************"; //用户的 SecretKey,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 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() {// 需要已经获取到临时密钥的结果:tmp_secret_id、tmp_secret_key、// 临时密钥的生成参见 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"; // 复制后对象名称std::string source = bucket_name + ".cos." + region + ".myqcloud.com/test_src.txt"; ; // 复制源对象// 设置分块拷贝的分块大小,默认20MB,最大支持5GB,最小支持1MB// 此配置是全局性配置,主动设置后,后续初始化的所有CopyReq,都使用此配置CosSysConfig::SetUploadCopyPartSize(20 * 1024 * 1024);qcloud_cos::CopyReq req(bucket_name, object_name);// 目标存储桶名和对象名qcloud_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;}
参数名称 | 描述 | 类型 |
req | 拷贝文件请求 | CopyReq |
resp | 拷贝文件响应 | CopyResp |
成员或函数 | 描述 | 参数类型 |
bucket_name | 目标存储桶名,可通过构造函数或 set 方法进行设置 | string |
object_name | 目标对象键(Key),可通过构造函数或 set 方法进行设置 是对象在存储桶中的唯一标识。例如,在对象的访问域名 examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/picture.jpg 中,对象键为 doc/picture.jpg,详情请参见 对象键 | string |
SetXCosCopySource | 用于设置拷贝源对象地址。 | string |
成员函数 | 描述 | 返回类型 |
GetVersionId | 获取 Object 的版本号, 如果 Bucket 未开启多版本, 返回空字符串 | string |
GetXCosServerSideEncryption | 获取 Server 端加密使用的算法 | string |
GetEtag | 获取存储上传对象的 Etag | string |
GetXCosRequestId | 获取请求 ID | string |
成员函数 | 描述 | 参数类型 |
SetUploadCopyPartSize | 设置分块拷贝的块大小,单位:字节(Byte),默认为20MB 设置方法为CosSysConfig::SetUploadCopyPartSize(20 * 1024 * 1024) | uint64_t |
SetUploadThreadPoolSize | 设置下载线程池大小,默认为5。 设置方法为CosSysConfig::SetUploadThreadPoolSize(5) | unsigned |
成员函数 | 描述 | 返回类型 |
IsSucc | 判断是否成功,成功返回 true,失败返回 false | bool |
GetHttpStatus | 获取 http 状态码 | int |
GetErrorCode | 获取请求失败时获取错误码 | string |
GetErrorMsg | 获取请求失败时获取错误信息 | string |
GetXCosRequestId | 获取请求 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";// bucket 的地域,请参见 https://www.tencentcloud.com/document/product/436/62?from_cn_redirect=1std::string secret_id = "************************************"; //用户的 SecretId,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1std::string secret_key = "************************************"; //用户的 SecretKey,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 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() {// 需要已经获取到临时密钥的结果:tmp_secret_id、tmp_secret_key、// 临时密钥的生成参见 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"; // 复制目标对象名称std::string source = bucket_name + ".cos." + region + ".myqcloud.com/test.txt"; // 复制源对象qcloud_cos::PutObjectCopyReq req(bucket_name, object_name);// 目标存储桶名和对象名req.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;}
参数名称 | 描述 | 类型 |
req | 拷贝文件请求 | PutObjectCopyReq |
resp | 拷贝文件响应 | PutObjectCopyResp |
成员或函数 | 描述 | 参数类型 |
bucket_name | 目标存储桶名,可通过构造函数或 set 方法进行设置 | string |
object_name | 目标对象键(Key),可通过构造函数或 set 方法进行设置 是对象在存储桶中的唯一标识。例如,在对象的访问域名 examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/picture.jpg 中,对象键为 doc/picture.jpg,详情请参见 对象键 | string |
SetXCosCopySource | 用于设置拷贝源对象地址。 | string |
成员函数 | 描述 | 返回类型 |
GetVersionId | 获取 Object 的版本号, 如果 Bucket 未开启多版本, 返回空字符串 | string |
GetXCosServerSideEncryption | 获取 Server 端加密使用的算法 | string |
GetEtag | 获取存储上传对象的 Etag | string |
GetXCosRequestId | 获取请求 ID | string |
成员函数 | 描述 | 返回类型 |
IsSucc | 判断是否成功,成功返回 true,失败返回 false。 | bool |
GetHttpStatus | 获得 http 状态码。 | int |
GetErrorCode | 请求失败时获取错误码。 | string |
GetErrorMsg | 请求失败时获取错误信息。 | string |
GetXCosRequestId | 获取请求 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";// bucket 的地域,请参见 https://www.tencentcloud.com/document/product/436/62?from_cn_redirect=1std::string secret_id = "************************************"; //用户的 SecretId,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1std::string secret_key = "************************************"; //用户的 SecretKey,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参见 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() {// 需要已经获取到临时密钥的结果:tmp_secret_id、tmp_secret_key、// 临时密钥的生成参见 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;}
参数名称 | 描述 | 类型 |
req | 移动对象请求 | MoveObjectReq |
成员函数 | 描述 | 返回类型 |
IsSucc | 判断是否成功,成功返回 true,失败返回 false。 | bool |
GetHttpStatus | 获得 http 状态码。 | int |
GetErrorCode | 请求失败时获取错误码。 | string |
GetErrorMsg | 请求失败时获取错误信息。 | string |
GetXCosRequestId | 获取请求 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;}}
文档反馈