Release Notes
Announcements
cos:GetObject. For more authorization details, see CAM-supported APIs.Function Name | Description | Example code |
Querying Object Content | Using Structured Query Language (SQL) to search content from specified objects (in CSV, JSON, or Parquet format). |
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::SelectObjectContent(const SelectObjectContentReq& req, SelectObjectContentResp* resp)
void SelectObjectContentDemo(qcloud_cos::CosAPI& cos) {std::string object_name = "test.csv.gz";int input_file_type = CSV; // The format of the object to be searched is CSV or JSONint input_compress_type = COMPRESS_GZIP; // Compression type: COMPRESS_NONE, COMPRESS_GZIP, COMPRESS_BZIP2int out_file_type = CSV; // The output format is CSV or JSONqcloud_cos::SelectObjectContentReq req(bucket_name, object_name, input_file_type, input_compress_type, out_file_type);req.SetSqlExpression("Select * from COSObject");qcloud_cos::SelectObjectContentResp resp;qcloud_cos::CosResult result = cos.SelectObjectContent(req, &resp);std::cout << "=====================IsObjectExist=======================" << std::endl;PrintResult(result, resp);// Supports printing the final results to the terminal or writing to a local file.// resp.WriteResultToLocalFile("file_name");resp.PrintResult();std::cout << "=========================================================" << std::endl;}
Parameter Name | Description | Type |
req | Search Objects Request | SelectObjectContentReq |
resp | Search Objects Response | SelectObjectContentResp |
Member or Function | Description | Parameter Type |
bucket_name | 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 | 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 |
input_file_type | The format of the object to be searched can be set via the constructor or set method. | string |
input_compress_type | Compression type, which can be set via the constructor or set method. | string |
out_file_type | Output format, which can be set via the constructor or set method. | string |
Member functions | Description | Return Type |
PrintResult | Print the final results to the terminal. | None |
WriteResultToLocalFile | Write the final results to a local file. | None |
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;}}
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