Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

## [v5.5.10](https://github.com/tencentyun/cos-cpp-sdk-v5/compare/v5.5.9...v5.5.10) - 2023-03-06
## [v5.5.10](https://github.com/tencentyun/cos-cpp-sdk-v5/compare/v5.5.9...v5.5.10) - 2023-03-07

## What's Changed
* ut match stage 1 by @chen-honggang in https://github.com/tencentyun/cos-cpp-sdk-v5/pull/125
* fix: 主程序结束早于异步任务导致的crash by @Huberyxiao in https://github.com/tencentyun/cos-cpp-sdk-v5/pull/128
* 增加允许不签Host的接口&IsDomainSameToHost支持按实例单独配置 by @Huberyxiao in https://github.com/tencentyun/cos-cpp-sdk-v5/pull/130
* fix:修复PutObjectByStream接口 by @Huberyxiao in https://github.com/tencentyun/cos-cpp-sdk-v5/pull/131
* remove unnecessary sdk release library by @chen-honggang in https://github.com/tencentyun/cos-cpp-sdk-v5/pull/132
* 修复lcov数据不准确问题 by @chen-honggang in https://github.com/tencentyun/cos-cpp-sdk-v5/pull/133
* 修正lcov提取路径 by @chen-honggang in https://github.com/tencentyun/cos-cpp-sdk-v5/pull/134

## New Contributors
* @Huberyxiao made their first contribution in https://github.com/tencentyun/cos-cpp-sdk-v5/pull/128
Expand All @@ -23,6 +25,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

### Merged

- 修正lcov提取路径 [`#134`](https://github.com/tencentyun/cos-cpp-sdk-v5/pull/134)
- 修复lcov数据不准确问题 [`#133`](https://github.com/tencentyun/cos-cpp-sdk-v5/pull/133)
- remove unnecessary sdk release library [`#132`](https://github.com/tencentyun/cos-cpp-sdk-v5/pull/132)
- fix:修复PutObjectByStream接口 [`#131`](https://github.com/tencentyun/cos-cpp-sdk-v5/pull/131)
- 增加允许不签Host的接口&IsDomainSameToHost支持按实例单独配置 [`#130`](https://github.com/tencentyun/cos-cpp-sdk-v5/pull/130)
Expand All @@ -33,6 +37,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

- 增加允许不签Host的接口 [`7f87180`](https://github.com/tencentyun/cos-cpp-sdk-v5/commit/7f8718097a9efcc9b8dfa7a22f20632dfac0ebb3)
- IsDomainSameToHost支持按实例单独配置 [`072ff3d`](https://github.com/tencentyun/cos-cpp-sdk-v5/commit/072ff3d1d53fbd2daec34690f0cb5ac13956d527)
- Updated CHANGELOG.md [`4c0c85d`](https://github.com/tencentyun/cos-cpp-sdk-v5/commit/4c0c85d69534abbcfc79b3bae30231a2e2f433fc)
- Updated CHANGELOG.md [`4dced4b`](https://github.com/tencentyun/cos-cpp-sdk-v5/commit/4dced4b8242bda3a193165235bf111559421c5a4)
- fix:PutObjectByStream [`e1ea968`](https://github.com/tencentyun/cos-cpp-sdk-v5/commit/e1ea9685c73677763d765fa5cf92ed271e3b7250)

Expand Down
70 changes: 70 additions & 0 deletions demo/cos_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ void DeleteBucket(qcloud_cos::CosAPI& cos, const std::string& bucket_name) {

void PutBucket(qcloud_cos::CosAPI& cos, const std::string& bucket_name) {
qcloud_cos::PutBucketReq req(bucket_name);
//创建MAZ存储桶使用下方进行设置
//req.SetMAZBucket();
qcloud_cos::PutBucketResp resp;
qcloud_cos::CosResult result = cos.PutBucket(req, &resp);

Expand Down Expand Up @@ -327,6 +329,74 @@ void GetBucketACL(qcloud_cos::CosAPI& cos, const std::string& bucket_name) {
<< std::endl;
}

void GetBucketPolicy(qcloud_cos::CosAPI& cos,const std::string& bucket_name) {
qcloud_cos::GetBucketPolicyReq req(bucket_name);
qcloud_cos::GetBucketPolicyResp resp;
qcloud_cos::CosResult result = cos.GetBucketPolicy(req, &resp);

std::cout << resp.GetPolicy() << std::endl;
std::cout << "===================GetBucketPolicy====================="
<< std::endl;
PrintResult(result, resp);
std::cout
<< "===================================================================="
<< std::endl;
}

void PutBucketPolicy(qcloud_cos::CosAPI& cos,const std::string& bucket_name) {
qcloud_cos::PutBucketPolicyReq req(bucket_name);
qcloud_cos::PutBucketPolicyResp resp;
std::string bucket_policy =
" {"
" \"Statement\": ["
" {"
" \"Principal\": {"
" \"qcs\": ["
" \"qcs::cam::uin/100000000001:uin/100000000011\"" //替换成您想授予权限的账户 uin
" ]\n"
" },\n"
" \"Effect\": \"allow\","
" \"Action\": ["
" \"cos:PutObject\""
" ],\n"
" \"Resource\": [" //这里改成允许的路径前缀,可以根据自己网站的用户登录态判断允许上传的具体路径,例子: a.jpg 或者 a/* 或者 * (使用通配符*存在重大安全风险, 请谨慎评估使用)
" \"qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/exampleobject\""
" ],\n"
" \"Condition\": {"
" \"string_equal\": {"
" \"cos:x-cos-mime-limit\": \"image/jpeg\""
" }"
" }"
" }"
" ],"
" \"Version\": \"2.0\""
" }";
std::cout << bucket_policy << std::endl;
req.SetBody(bucket_policy);
qcloud_cos::CosResult result = cos.PutBucketPolicy(req, &resp);

std::cout << "===================PutBucketPolicy====================="
<< std::endl;
PrintResult(result, resp);
std::cout
<< "===================================================================="
<< std::endl;
}

void DeleteBucketPolicy(qcloud_cos::CosAPI& cos,const std::string& bucket_name) {
qcloud_cos::DeleteBucketPolicyReq req(bucket_name);
qcloud_cos::DeleteBucketPolicyResp resp;
qcloud_cos::CosResult result = cos.DeleteBucketPolicy(req, &resp);

std::cout << "===================DeleteBucketPolicy====================="
<< std::endl;
PrintResult(result, resp);
std::cout
<< "===================================================================="
<< std::endl;
}


void PutBucketCORS(qcloud_cos::CosAPI& cos, const std::string& bucket_name) {
qcloud_cos::PutBucketCORSReq req(bucket_name);
qcloud_cos::CORSRule rule;
Expand Down
Binary file added demo/test_file/audio.mp3
Binary file not shown.
Binary file added demo/test_file/document.docx
Binary file not shown.
Binary file added demo/test_file/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions demo/test_file/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
texttest
Binary file added demo/test_file/video.mp4
Binary file not shown.
10 changes: 5 additions & 5 deletions gen_lcov.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

workspace=`pwd`
EXTRACT="${workspace}/*/op/* ${workspace}/*/util/* ${workspace}/*/request/* ${workspace}/*/response/* ${workspace}/*/trsf/* ${workspace}/include"
EXTRACT="${workspace}/*/op/* ${workspace}/*/util/* ${workspace}/*/request/* ${workspace}/*/response/* ${workspace}/*/trsf/* ${workspace}/include/* ${workspace}/src/*"
# clear
rm UTReport -rf
rm UTResport.tar
Expand Down Expand Up @@ -39,8 +39,8 @@ lcov --extract sevenyou.info ${EXTRACT} -o sevenyou_filted.info
genhtml -o UTReport --prefix=`pwd` sevenyou_init_filted.info sevenyou_filted.info
tar -cvf UTReport.tar UTReport

rm sevenyou_init.info
rm sevenyou_init_filted.info
rm sevenyou.info
rm sevenyou_filted.info
# rm sevenyou_init.info
# rm sevenyou_init_filted.info
# rm sevenyou.info
# rm sevenyou_filted.info
rm UTReport -rf
40 changes: 39 additions & 1 deletion include/cos_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CosAPI {
bool IsObjectExist(const std::string& bucket_name,
const std::string& object_name);

/// \brief 创建一个Bucket
/// \brief List Buckets
/// 详见: https://cloud.tencent.com/document/api/436/8291
///
/// \param req GetService请求
Expand Down Expand Up @@ -189,6 +189,30 @@ class CosAPI {
/// \return 本次请求的调用情况(如状态码等)
CosResult PutBucketACL(const PutBucketACLReq& req, PutBucketACLResp* resp);

/// \brief 获取Bucket的权限策略
///
/// \param req GetBucketPolicy请求
/// \param resp GetBucketPolicy返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult GetBucketPolicy(const GetBucketPolicyReq& req, GetBucketPolicyResp* resp);

/// \brief 写入/替换Bucket的权限策略,通过Body传入
///
/// \param req PutBucketPolicy请求
/// \param resp PutBucketPolicy返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult PutBucketPolicy(const PutBucketPolicyReq& req, PutBucketPolicyResp* resp);

/// \brief 删除Bucket的权限策略
///
/// \param req DeleteBucketPolicy请求
/// \param resp DeleteBucketPolicy返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult DeleteBucketPolicy(const DeleteBucketPolicyReq& req, DeleteBucketPolicyResp* resp);

/// \brief 列出Bucket下的CORS
///
/// \param req GetBucketCORS请求
Expand Down Expand Up @@ -741,6 +765,12 @@ class CosAPI {
SharedAsyncContext AsyncGetObject(const AsyncGetObjectReq& req);
SharedAsyncContext AsyncGetObject(const AsyncGetObjectReq& req, Poco::TaskManager*& taskManager);

/// \brief 异步多线程下载对象到本地,支持断点续传
/// \param req AsyncResumableGetObject
/// \return 返回context
SharedAsyncContext AsyncResumableGetObject(const AsyncGetObjectReq& req);
SharedAsyncContext AsyncResumableGetObject(const AsyncGetObjectReq& req, Poco::TaskManager*& taskManager);;

/// \brief 异步多线程下载对象到本地
/// \param req MultiGetObjectAsync请求
/// \return 返回context
Expand Down Expand Up @@ -776,6 +806,10 @@ class CosAPI {

/* 数据处理接口 */

/*** 存储桶绑定万象服务 ***/
CosResult PutBucketToCI(const PutBucketToCIReq& req,
PutBucketToCIResp* resp);

/** 基础图片处理 **/

/** 图片持久化处理 **/
Expand Down Expand Up @@ -833,6 +867,10 @@ class CosAPI {
CosResult DescribeMediaBuckets(const DescribeMediaBucketsReq& req,
DescribeMediaBucketsResp* resp);

/*** 存储桶绑定媒体处理 ***/
CosResult CreateMediaBucket(const CreateMediaBucketReq& req,
CreateMediaBucketResp* resp);

/*** 获取媒体文件某个时间的截图 ***/
// https://cloud.tencent.com/document/product/436/55671
CosResult GetSnapshot(const GetSnapshotReq& req, GetSnapshotResp* resp);
Expand Down
4 changes: 4 additions & 0 deletions include/cos_sys_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class CosSysConfig {
static std::string GetCIHost(const std::string& bucket_name,
const std::string& region);

/// \brief 获取PIC域名
static std::string GetPICHost(uint64_t app_id, const std::string& region,
const std::string& bucket_name);

static std::string GetDestDomain();

/// \brief 获取是否使用特定ip和端口号
Expand Down
41 changes: 41 additions & 0 deletions include/op/bucket_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,30 @@ class BucketOp : public BaseOp {
/// \return 本次请求的调用情况(如状态码等)
CosResult PutBucketACL(const PutBucketACLReq& req, PutBucketACLResp* resp);

/// \brief 获取Bucket的权限策略
///
/// \param req GetBucketPolicy请求
/// \param resp GetBucketPolicy返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult GetBucketPolicy(const GetBucketPolicyReq& req, GetBucketPolicyResp* resp);

/// \brief 写入/替换Bucket的权限策略,通过Body传入
///
/// \param req PutBucketPolicy请求
/// \param resp PutBucketPolicy返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult PutBucketPolicy(const PutBucketPolicyReq& req, PutBucketPolicyResp* resp);

/// \brief 删除Bucket的权限策略
///
/// \param req DeleteBucketPolicy请求
/// \param resp DeleteBucketPolicy返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult DeleteBucketPolicy(const DeleteBucketPolicyReq& req, DeleteBucketPolicyResp* resp);

/// \brief 列出Bucket下的CORS
///
/// \param req GetBucketCORS请求
Expand Down Expand Up @@ -379,6 +403,15 @@ class BucketOp : public BaseOp {
const GetBucketIntelligentTieringReq& req,
GetBucketIntelligentTieringResp* resp);

/// \brief 存储桶绑定ci
///
/// \param req PutBucketToCIReq请求
/// \param resp PutBucketToCIResp返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult PutBucketToCI(const PutBucketToCIReq& req,
PutBucketToCIResp* resp);

/// \brief 提交文档转码任务
/// \brief https://cloud.tencent.com/document/product/436/54056
/// \param req CreateDocProcessJobs请求
Expand Down Expand Up @@ -432,6 +465,14 @@ class BucketOp : public BaseOp {
CosResult DescribeMediaBuckets(const DescribeMediaBucketsReq& req,
DescribeMediaBucketsResp* resp);

/// \brief 开通媒体处理
/// \brief https://cloud.tencent.com/document/product/436/72824
/// \param req DescribeMediaBuckets请求
/// \param resp DescribeMediaBuckets返回
///
/// \return 本次请求的调用情况(如状态码等)
CosResult CreateMediaBucket(const CreateMediaBucketReq& req,
CreateMediaBucketResp* resp);
/// \brief 获取媒体文件信息
/// \brief https://cloud.tencent.com/document/product/436/55672
/// \param req GetMediainfo请求
Expand Down
3 changes: 2 additions & 1 deletion include/op/object_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ class ObjectOp : public BaseOp {

/// \brief 支持断点下载
CosResult ResumableGetObject(const GetObjectByFileReq& req,
GetObjectByFileResp* resp);
GetObjectByFileResp* resp,
const SharedTransferHandler& handler = nullptr);

/*批量及目录操作接口*/
CosResult PutObjects(const PutObjectsByDirectoryReq& req,
Expand Down
41 changes: 41 additions & 0 deletions include/request/bucket_req.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ class PutBucketReq : public BucketReq {
void SetXCosGrantFullControl(const std::string& str) {
AddHeader("x-cos-grant-full-control", str);
}

//设置桶为多az存储桶
void SetMAZBucket() {
std::string maz = "<CreateBucketConfiguration>";
maz += " <BucketAZConfig>MAZ</BucketAZConfig>";
maz += "</CreateBucketConfiguration>";
SetBody(maz);
}
};

class GetBucketReq : public BucketReq {
Expand Down Expand Up @@ -354,6 +362,39 @@ class PutBucketACLReq : public BucketReq {
std::vector<Grant> m_acl;
};

class GetBucketPolicyReq : public BucketReq {
public:
GetBucketPolicyReq(const std::string& bucket_name) : BucketReq(bucket_name) {
SetMethod("GET");
SetPath("/");
AddParam("policy", "");
}

virtual ~GetBucketPolicyReq() {}
};

class PutBucketPolicyReq : public BucketReq {
public:
PutBucketPolicyReq(const std::string& bucket_name) : BucketReq(bucket_name) {
SetMethod("PUT");
SetPath("/");
AddParam("policy", "");
}

virtual ~PutBucketPolicyReq() {}
};

class DeleteBucketPolicyReq : public BucketReq {
public:
DeleteBucketPolicyReq(const std::string& bucket_name) : BucketReq(bucket_name) {
SetMethod("DELETE");
SetPath("/");
AddParam("policy", "");
}

virtual ~DeleteBucketPolicyReq() {}
};

class DeleteBucketACLReq : public BucketReq {
public:
DeleteBucketACLReq(const std::string& bucket_name) : BucketReq(bucket_name) {
Expand Down
Loading