Release Notes
Announcements
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, tmp_secret_id, tmp_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;}
void PutObjectByFileDemo(qcloud_cos::CosAPI& cos) {std::string object_name = "test.txt";std::string file_path = "./test_file/text.txt";qcloud_cos::PutObjectByFileReq req(bucket_name, object_name, file_path);req.SetXCosServerSideEncryption("AES256");qcloud_cos::PutObjectByFileResp resp;qcloud_cos::CosResult result = cos.PutObject(req, &resp);std::cout << "====================PutObjectByFile======================" << std::endl;PrintResult(result, resp);std::cout << "=========================================================" << std::endl;}
void PutObjectByFileDemo(qcloud_cos::CosAPI& cos) {std::string object_name = "test.txt";std::string file_path = "./test_file/text.txt";qcloud_cos::PutObjectByFileReq req(bucket_name, object_name, file_path);req.SetHttps();req.TurnOffComputeConentMd5();req.AddHeader("x-cos-server-side-encryption-customer-algorithm", "AES256"); // Server-side encryption algorithm, currently only supports AES256req.AddHeader("x-cos-server-side-encryption-customer-key","key"); // Base64-encoded server-side encryption key, e.g., MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=req.AddHeader("x-cos-server-side-encryption-customer-key-MD5","key-MD5"); // MD5 hash value of the server-side encryption key, Base64-encoded, e.g., U5L61r7jcwdNvT7frmUG8g==// The Base64 encoding of the MD5 hash value must be calculated based on the binary-encoded MD5.qcloud_cos::PutObjectByFileResp resp;qcloud_cos::CosResult result = cos.PutObject(req, &resp);std::cout << "====================PutObjectByFile======================" << std::endl;PrintResult(result, resp);std::cout << "=========================================================" << std::endl;}void GetObjectByFileDemo(qcloud_cos::CosAPI& cos) {std::string object_name = "test.txt";std::string file_path = "./test_file/text2.txt";qcloud_cos::GetObjectByFileReq req(bucket_name, object_name, file_path);req.SetHttps();req.SetCheckMD5(false);req.AddHeader("x-cos-server-side-encryption-customer-algorithm", "AES256"); // Server-side encryption algorithm, currently only supports AES256req.AddHeader("x-cos-server-side-encryption-customer-key","key"); // Base64-encoded server-side encryption key, e.g., MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=req.AddHeader("x-cos-server-side-encryption-customer-key-MD5","key-MD5"); // MD5 hash value of the server-side encryption key, Base64-encoded, e.g., U5L61r7jcwdNvT7frmUG8g==qcloud_cos::GetObjectByFileResp resp;qcloud_cos::CosResult result = cos.GetObject(req, &resp);std::cout << "===================GetObjectResponse=====================" << std::endl;PrintResult(result, resp);std::cout << "=========================================================" << std::endl;}
void PutObjectByFileDemo(qcloud_cos::CosAPI& cos) {std::string object_name = "test.txt";std::string file_path = "./test_file/text.txt";qcloud_cos::PutObjectByFileReq req(bucket_name, object_name, file_path);req.SetXCosServerSideEncryption("cos/kms");req.TurnOffComputeConentMd5();req.AddHeader("x-cos-server-side-encryption-cos-kms-key-id","key-id"); // Specifies the KMS Customer Master Key (CMK). If not specified, the CMK created by default for COS will be usedreq.AddHeader("x-cos-server-side-encryption-context","context"); // Specifies the encryption context, which is the Base64-encoded JSON-formatted key-value pairs. For example, eyJhIjoiYXNkZmEiLCJiIjoiMTIzMzIxIn0=qcloud_cos::PutObjectByFileResp resp;qcloud_cos::CosResult result = cos.PutObject(req, &resp);std::cout << "====================PutObjectByFile======================" << std::endl;PrintResult(result, resp);std::cout << "=========================================================" << std::endl;}void GetObjectByFileDemo(qcloud_cos::CosAPI& cos) {std::string object_name = "test.txt";std::string file_path = "./test_file/text2.txt";qcloud_cos::GetObjectByFileReq req(bucket_name, object_name, file_path);req.SetHttps();req.SetCheckMD5(false);qcloud_cos::GetObjectByFileResp resp;qcloud_cos::CosResult result = cos.GetObject(req, &resp);std::cout << "===================GetObjectResponse=====================" << std::endl;PrintResult(result, resp);std::cout << "=========================================================" << std::endl;}
Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários