diff --git a/README.md b/README.md index 07bc111..aa2d37f 100644 --- a/README.md +++ b/README.md @@ -296,7 +296,7 @@ int main(int argc, char *argv[]) { // 创建成功 } else { // 创建存储桶失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等 - std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl; + std::cout << "ErrorInfo=" << 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; @@ -341,7 +341,7 @@ int main(int argc, char *argv[]) { // 查询存储桶列表成功 } else { // 查询存储桶列表失败,可以调用 CosResult 的成员函数输出错误信息,比如 requestID 等 - std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl; + std::cout << "ErrorInfo=" << 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; @@ -380,7 +380,7 @@ int main(int argc, char *argv[]) { // 上传文件成功 } else { // 上传文件失败,可以调用 CosResult 的成员函数输出错误信息,比如 requestID 等 - std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl; + std::cout << "ErrorInfo=" << 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; @@ -421,7 +421,7 @@ int main(int argc, char *argv[]) { // 查询对象列表成功 } else { // 查询对象列表失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等 - std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl; + std::cout << "ErrorInfo=" << 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; @@ -460,7 +460,7 @@ int main(int argc, char *argv[]) { // 下载文件成功 } else { // 下载文件失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等 - std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl; + std::cout << "ErrorInfo=" << 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; @@ -496,7 +496,7 @@ int main(int argc, char *argv[]) { // 删除对象成功 } else { // 删除对象失败,可以调用 CosResult 的成员函数输出错误信息,例如 requestID 等 - std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl; + std::cout << "ErrorInfo=" << 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; diff --git a/cos-cpp-sdk.md b/cos-cpp-sdk.md index 51321c0..630fe4e 100644 --- a/cos-cpp-sdk.md +++ b/cos-cpp-sdk.md @@ -139,7 +139,7 @@ static std::string Sign(const std::string& secret_id, `string GetXCosTraceId()`, 当请求出错时,服务端将会自动为这个错误生成一个唯一的 ID。使用遇到问题时,trace-id能更快地协助 COS 定位问题。当请求出错时,trace-id与request-id一一对应。 -`string GetErrorInfo()`, 获取sdk内部错误信息。 +`string GetErrorMsg()`, 获取sdk内部错误信息。 `int GetHttpStatus()`, 获取http状态码。 @@ -242,7 +242,7 @@ if (result.IsSucc()) { std::cout << "Marker=" << resp.GetMarker() << std::endl; std::cout << "MaxKeys=" << resp.GetMaxKeys() << std::endl; } else { - std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl; + std::cout << "ErrorInfo=" << 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; @@ -1509,7 +1509,7 @@ std::string object_name = "object_name"; do sth } else { // 调用失败,调用result的成员函数获取错误信息 - std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl; + std::cout << "ErrorInfo=" << 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; @@ -1532,7 +1532,7 @@ std::string object_name = "object_name"; do sth } else { // 调用失败,调用result的成员函数获取错误信息 - std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl; + std::cout << "ErrorInfo=" << 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; @@ -1804,21 +1804,21 @@ Multipart Upload封装了初始化分块上传、分块上传、完成分块上 #### 方法原型 ```cpp -CosResult MultiUploadObject(const MultiUploadObjectReq& request, MultiUploadObjectResp* response); +CosResult MultiUploadObject(const MultiPutObjectReq& request, MultiPutObjectResp* response); ``` #### 参数说明 -- req —— MultiUploadObjectReq MultiUploadObject操作的请求 +- req —— MultiPutObjectReq MultiUploadObject操作的请求 -MultiUploadObjectReq需要在构造的时候指明bucket、object以及待上传文件的本地路径, 如果不指明本地路径,则默认是当前工作路径下与object同名的文件。 +MultiPutObjectReq需要在构造的时候指明bucket、object以及待上传文件的本地路径, 如果不指明本地路径,则默认是当前工作路径下与object同名的文件。 ``` cpp -MultiUploadObjectReq(const std::string& bucket_name, +MultiPutObjectReq(const std::string& bucket_name, const std::string& object_name, const std::string& local_file_path = ""); ``` -- resp —— MultiUploadObjectResp MultiUploadObject操作的返回 +- resp —— MultiPutObjectResp MultiUploadObject操作的返回 分块上传成功的情况下,该Response的返回内容与CompleteMultiUploadResp一致。 分块上传失败的情况下,该Response根据不同的失败情况,返回内容与InitMultiUploadResp、UploadPartDataResp、CompleteMultiUploadResp一致。可调用`GetRespTag()`来获取具体失败在哪一步。 @@ -1831,8 +1831,8 @@ std::string GetRespTag(); #### 示例 ``` cpp -qcloud_cos::MultiUploadObjectReq req( bucket_name, object_name, "/temp/demo_6G.tmp"); -qcloud_cos::MultiUploadObjectResp resp; +qcloud_cos::MultiPutObjectReq req( bucket_name, object_name, "/temp/demo_6G.tmp"); +qcloud_cos::MultiPutObjectResp resp; qcloud_cos::CosResult result = cos.MultiUploadObject(req, &resp); if (result.IsSucc()) { diff --git a/demo/cos_demo.cpp b/demo/cos_demo.cpp index f3d4aca..6d89c96 100644 --- a/demo/cos_demo.cpp +++ b/demo/cos_demo.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "cos_api.h" @@ -23,7 +24,7 @@ void PrintResult(const qcloud_cos::CosResult& result, if (result.IsSucc()) { std::cout << resp.DebugString() << std::endl; } else { - std::cout << "ErrorInfo=" << result.GetErrorInfo() << std::endl; + 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; @@ -625,10 +626,10 @@ void CompleteMultiUpload(qcloud_cos::CosAPI& cos, void MultiUploadObject(qcloud_cos::CosAPI& cos, const std::string& bucket_name, const std::string& object_name, const std::string& local_file) { - qcloud_cos::MultiUploadObjectReq req(bucket_name, object_name, local_file); + qcloud_cos::MultiPutObjectReq req(bucket_name, object_name, local_file); req.SetRecvTimeoutInms(1000 * 60); - qcloud_cos::MultiUploadObjectResp resp; - qcloud_cos::CosResult result = cos.MultiUploadObject(req, &resp); + qcloud_cos::MultiPutObjectResp resp; + qcloud_cos::CosResult result = cos.PutObject(req, &resp); if (result.IsSucc()) { std::cout << "MultiUpload Succ." << std::endl; @@ -662,11 +663,11 @@ void MultiUploadObjectWideChar(qcloud_cos::CosAPI& cos, const std::string& bucket_name) { std::string local_file = "./안녕하십니까.mp4"; std::string object_name = "안녕하십니까.mp4"; - qcloud_cos::MultiUploadObjectReq req(bucket_name, object_name, local_file); + qcloud_cos::MultiPutObjectReq req(bucket_name, object_name, local_file); req.SetWideCharPath(); // 需要调用该函数 req.SetRecvTimeoutInms(1000 * 60); - qcloud_cos::MultiUploadObjectResp resp; - qcloud_cos::CosResult result = cos.MultiUploadObject(req, &resp); + qcloud_cos::MultiPutObjectResp resp; + qcloud_cos::CosResult result = cos.PutObject(req, &resp); if (result.IsSucc()) { std::cout << "MultiUploadObjectWideChar Succ." << std::endl; @@ -693,15 +694,15 @@ void MultiUploadObjectLimitTraffic(qcloud_cos::CosAPI& cos, const std::string& local_file, const uint64_t traffic_limit, bool set_header = true) { - qcloud_cos::MultiUploadObjectReq req(bucket_name, object_name, local_file); + qcloud_cos::MultiPutObjectReq req(bucket_name, object_name, local_file); if (set_header) { req.SetTrafficLimitByHeader(StringUtil::Uint64ToString(traffic_limit)); } else { req.SetTrafficLimitByParam(StringUtil::Uint64ToString(traffic_limit)); } req.SetRecvTimeoutInms(1000 * 60); - qcloud_cos::MultiUploadObjectResp resp; - qcloud_cos::CosResult result = cos.MultiUploadObject(req, &resp); + qcloud_cos::MultiPutObjectResp resp; + qcloud_cos::CosResult result = cos.PutObject(req, &resp); if (result.IsSucc()) { std::cout << "MultiUpload Succ." << std::endl; @@ -1659,88 +1660,118 @@ static void ProgressCallback(uint64_t transferred_size, uint64_t total_size, } } -static void StatusCallback(const std::string& status, void* user_data) { - qcloud_cos::ObjectReq* req = static_cast(user_data); - std::cout << "ObjectName:" << req->GetObjectName() - << ", CurrentStatus:" << status << std::endl; +static void MultiGetObjectAsyncDoneCallback(const SharedAsyncContext& context, + void* user_data) { + std::cout << "MultiGetObjectAsyncDoneCallback, BucketName:" + << context->GetBucketName() + << ", ObjectName:" << context->GetObjectName() + << ", LocalFile:" << context->GetLocalFilePath() << std::endl; + // qcloud_cos::MultiGetObjectReq对应的响应为qcloud_cos::MultiGetObjectResp + if (context->GetResult().IsSucc()) { + // 获取响应 + std::cout << "MultiGetObjectAsync succeed" << std::endl; + std::cout << "Result:" << context->GetResult().DebugString() << std::endl; + MultiGetObjectResp resp = context->GetMultiGetObjectResp(); + std::cout << "ETag:" << resp.GetEtag() << std::endl; + std::cout << "Crc64:" << resp.GetXCosHashCrc64Ecma() << std::endl; + } else { + std::cout << "MultiGetObjectAsync failed" << std::endl; + std::cout << "ErrorMsg:" << context->GetResult().GetErrorMsg() << std::endl; + } } - // 异步下载对象,支持更新下载进度 -void GetObjectAsync(qcloud_cos::CosAPI& cos, const std::string& bucket_name, - const std::string& object_name, - const std::string& file_path) { +void MultiGetObjectAsync(qcloud_cos::CosAPI& cos, + const std::string& bucket_name, + const std::string& object_name, + const std::string& file_path) { qcloud_cos::MultiGetObjectReq req(bucket_name, object_name, file_path); - qcloud_cos::MultiGetObjectResp resp; // 设置进度回调 req.SetTransferProgressCallback(&ProgressCallback); // 设置状态回调 - req.SetTransferStatusCallback(&StatusCallback); + req.SetDoneCallback(&MultiGetObjectAsyncDoneCallback); // 设置私有数据 - req.SetTransferCallbackUserData(&req); + req.SetUserData(&req); // 开始下载 - SharedTransferHandler handler = cos.GetObjectAsync(req, &resp); + SharedAsyncContext context = cos.GetObjectAsync(req); // 等待下载结束 - handler->WaitUntilFinish(); + context->WaitUntilFinish(); // 检查结果 - if (handler->m_result.IsSucc()) { - std::cout << "GetObjectAsync Succ." << std::endl; - std::cout << "Etag:" << resp.GetEtag() << std::endl; - std::cout << "ContentLength:" << resp.GetContentLength() << std::endl; + if (context->GetResult().IsSucc()) { + // 获取响应 + std::cout << "MultiGetObjectAsync succeed" << std::endl; + std::cout << "Result:" << context->GetResult().DebugString() << std::endl; + MultiGetObjectResp resp = context->GetMultiGetObjectResp(); + std::cout << "ETag:" << resp.GetEtag() << std::endl; + std::cout << "Crc64:" << resp.GetXCosHashCrc64Ecma() << std::endl; } else { - std::cout << "GetObjectAsync Fail." << std::endl; - std::cout << "ErrorMsg:" << handler->m_result.GetErrorMsg() << std::endl; + std::cout << "MultiGetObjectAsync failed" << std::endl; + std::cout << "ErrorMsg:" << context->GetResult().GetErrorMsg() << std::endl; + } + std::this_thread::sleep_for(std::chrono::seconds(1)); +} + +static void MultiPutObjectAsyncDoneCallback(const SharedAsyncContext& context, + void* user_data) { + std::cout << "MultiPutObjectAsyncDoneCallback, BucketName:" + << context->GetBucketName() + << ", ObjectName:" << context->GetObjectName() + << ", LocalFile:" << context->GetLocalFilePath() << std::endl; + // qcloud_cos::MultiPutObjectReq对应的响应为qcloud_cos::MultiPutObjectResp + if (context->GetResult().IsSucc()) { + // 获取响应 + std::cout << "MultiPutObjectAsync succeed" << std::endl; + std::cout << "Result:" << context->GetResult().DebugString() << std::endl; + MultiPutObjectResp resp = context->GetMultiPutObjectResp(); + std::cout << "Location:" << resp.GetLocation() << std::endl; + std::cout << "Bucket:" << resp.GetBucket() << std::endl; + std::cout << "Key:" << resp.GetKey() << std::endl; + std::cout << "ETag:" << resp.GetEtag() << std::endl; + std::cout << "Crc64:" << resp.GetXCosHashCrc64Ecma() << std::endl; + } else { + std::cout << "MultiGetObjectAsync failed" << std::endl; + std::cout << "ErrorMsg:" << context->GetResult().GetErrorMsg() << std::endl; } - std::cout << "===================GetObjectAsync=============================" - << std::endl; - PrintResult(handler->m_result, resp); - std::cout << "========================================================" - << std::endl; } // 异步多上传对象,支持更新上传进度 -void PutObjectAsync(qcloud_cos::CosAPI& cos, const std::string& bucket_name, - const std::string& object_name, - const std::string& local_file) { - qcloud_cos::MultiUploadObjectReq req(bucket_name, object_name, local_file); - qcloud_cos::MultiUploadObjectResp resp; +void MultiPutObjectAsync(qcloud_cos::CosAPI& cos, + const std::string& bucket_name, + const std::string& object_name, + const std::string& local_file) { + qcloud_cos::MultiPutObjectReq req(bucket_name, object_name, local_file); req.SetRecvTimeoutInms(1000 * 60); // 设置上传进度回调 req.SetTransferProgressCallback(&ProgressCallback); // 设置上传状态回调 - req.SetTransferStatusCallback(&StatusCallback); + req.SetDoneCallback(&MultiPutObjectAsyncDoneCallback); // 设置私有数据 - req.SetTransferCallbackUserData(&req); + req.SetUserData(&req); // 开始上传 - SharedTransferHandler handler = cos.PutObjectAsync(req, &resp); + SharedAsyncContext context = cos.PutObjectAsync(req); // 等待上传结束 - handler->WaitUntilFinish(); + std::cout << "wait finish..." << std::endl; + context->WaitUntilFinish(); // 检查结果 - if (handler->m_result.IsSucc()) { - std::cout << "PutObjectAsync Succ." << std::endl; - std::cout << "Etag:" << resp.GetEtag() << std::endl; + if (context->GetResult().IsSucc()) { + // 获取响应 + std::cout << "MultiPutObjectAsync succeed" << std::endl; + std::cout << "Result:" << context->GetResult().DebugString() << std::endl; + MultiPutObjectResp resp = context->GetMultiPutObjectResp(); + std::cout << "Location:" << resp.GetLocation() << std::endl; + std::cout << "Bucket:" << resp.GetBucket() << std::endl; + std::cout << "Key:" << resp.GetKey() << std::endl; + std::cout << "ETag:" << resp.GetEtag() << std::endl; + std::cout << "Crc64:" << resp.GetXCosHashCrc64Ecma() << std::endl; } else { - std::cout << "PutObjectAsync Fail." << std::endl; - // 获取具体失败在哪一步 - std::string resp_tag = resp.GetRespTag(); - if ("Init" == resp_tag) { - // print result - } else if ("Upload" == resp_tag) { - // print result - } else if ("Complete" == resp_tag) { - // print result - } + std::cout << "MultiPutObjectAsync failed" << std::endl; + std::cout << "ErrorMsg:" << context->GetResult().GetErrorMsg() << std::endl; } - std::cout << "===================PutObjectAsync=============================" - << std::endl; - PrintResult(handler->m_result, resp); - std::cout << "========================================================" - << std::endl; } // 从目录上传文件 @@ -2600,7 +2631,7 @@ int main(int argc, char** argv) { // // Copy(cos, bucket_name, "sevenyou_6G_diff_region_copy_part", // "sevenyoutest-123456.cos.ap-beijing-1.myqcloud.com/sevenyou_6G"); - // //MultiUploadObject(cos, bucket_name, "sevenyou_e2_multi", + // MultiUploadObject(cos, bucket_name, "test", "/tmp/testfile10GB"); // "/data/sevenyou/temp/seven_50M.tmp.0925"); // //MultiUploadObject(cos, bucket_name, "sevenyou_1102_north_multi", // "/data/sevenyou/temp/seven_50M.tmp.0925"); @@ -2803,8 +2834,8 @@ int main(int argc, char** argv) { // async //{ - // PutObjectAsync(cos, bucket_name, "bigfile", "./bigfile"); - // GetObjectAsync(cos, bucket_name, "bigfile", "./bigfile_download"); + // MultiPutObjectAsync(cos, bucket_name, "bigfile", "./bigfile"); + // MultiGetObjectAsync(cos, bucket_name, "bigfile", "./bigfile_download"); //} //{ diff --git a/include/cos_api.h b/include/cos_api.h index e062a67..658be46 100644 --- a/include/cos_api.h +++ b/include/cos_api.h @@ -5,7 +5,6 @@ #include "op/cos_result.h" #include "op/object_op.h" #include "op/service_op.h" -#include "trsf/transfer_handler.h" #include "util/auth_tool.h" #include "util/codec_util.h" @@ -28,7 +27,7 @@ class CosAPI { std::string GetBucketLocation(const std::string& bucket_name); /// \brief 生成一个预签名链接 - std::string GeneratePresignedUrl(const GeneratePresignedUrlReq& request); + std::string GeneratePresignedUrl(const GeneratePresignedUrlReq& req); /// \brief 生成一个预签名链接 std::string GeneratePresignedUrl(const std::string& bucket_name, @@ -53,11 +52,11 @@ class CosAPI { /// \brief 创建一个Bucket /// 详见: https://cloud.tencent.com/document/api/436/8291 /// - /// \param request GetService请求 - /// \param response GetService返回 + /// \param req GetService请求 + /// \param resp GetService返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetService(const GetServiceReq& request, GetServiceResp* response); + CosResult GetService(const GetServiceReq& req, GetServiceResp* resp); /// \brief 创建一个Bucket /// 详见: https://www.qcloud.com/document/product/436/7738 @@ -66,7 +65,7 @@ class CosAPI { /// \param resp PutBucket返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucket(const PutBucketReq& request, PutBucketResp* response); + CosResult PutBucket(const PutBucketReq& req, PutBucketResp* resp); /// \brief 确认Bucket是否存在 /// (详见:https://cloud.tencent.com/document/product/436/7735) @@ -75,19 +74,19 @@ class CosAPI { /// \param resp HeadBucket返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult HeadBucket(const HeadBucketReq& request, HeadBucketResp* response); + CosResult HeadBucket(const HeadBucketReq& req, HeadBucketResp* resp); /// \brief 列出该Bucket下的部分或者全部Object, 需要对Bucket有Read 权限 /// 详见: https://www.qcloud.com/document/product/436/7734 /// - /// \param request GetBucket请求 - /// \param response GetBucket返回 + /// \param req GetBucket请求 + /// \param resp GetBucket返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult GetBucket(const GetBucketReq& request, GetBucketResp* response); + CosResult GetBucket(const GetBucketReq& req, GetBucketResp* resp); - CosResult ListMultipartUpload(const ListMultipartUploadReq& request, - ListMultipartUploadResp* response); + CosResult ListMultipartUpload(const ListMultipartUploadReq& req, + ListMultipartUploadResp* resp); /// \brief 删除Bucket /// 详见: https://cloud.tencent.com/document/product/436/7732 @@ -96,8 +95,7 @@ class CosAPI { /// \param resp DeleteBucket返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteBucket(const DeleteBucketReq& request, - DeleteBucketResp* response); + CosResult DeleteBucket(const DeleteBucketReq& req, DeleteBucketResp* resp); /// \brief 获得存储桶的版本控制信息 /// (详见:https://cloud.tencent.com/document/product/436/8597) @@ -125,8 +123,8 @@ class CosAPI { /// \param resp GetBucketReplication返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketReplication(const GetBucketReplicationReq& request, - GetBucketReplicationResp* response); + CosResult GetBucketReplication(const GetBucketReplicationReq& req, + GetBucketReplicationResp* resp); /// \brief 增加/替换Bucket下的跨域复制配置 /// @@ -134,8 +132,8 @@ class CosAPI { /// \param resp PutBucketReplication返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketReplication(const PutBucketReplicationReq& request, - PutBucketReplicationResp* response); + CosResult PutBucketReplication(const PutBucketReplicationReq& req, + PutBucketReplicationResp* resp); /// \brief 删除Bucket下的跨域复制配置 /// @@ -143,8 +141,8 @@ class CosAPI { /// \param resp DeleteBucketReplication返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteBucketReplication(const DeleteBucketReplicationReq& request, - DeleteBucketReplicationResp* response); + CosResult DeleteBucketReplication(const DeleteBucketReplicationReq& req, + DeleteBucketReplicationResp* resp); /// \brief 列出Bucket下的生命周期配置 /// @@ -152,8 +150,8 @@ class CosAPI { /// \param resp GetBucketLifecycle返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketLifecycle(const GetBucketLifecycleReq& request, - GetBucketLifecycleResp* response); + CosResult GetBucketLifecycle(const GetBucketLifecycleReq& req, + GetBucketLifecycleResp* resp); /// \brief 增加/替换Bucket下的生命周期配置 /// @@ -161,8 +159,8 @@ class CosAPI { /// \param resp PutBucketLifecycle返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketLifecycle(const PutBucketLifecycleReq& request, - PutBucketLifecycleResp* response); + CosResult PutBucketLifecycle(const PutBucketLifecycleReq& req, + PutBucketLifecycleResp* resp); /// \brief 删除Bucket下的生命周期配置 /// @@ -170,8 +168,8 @@ class CosAPI { /// \param resp DeleteBucketLifecycle返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteBucketLifecycle(const DeleteBucketLifecycleReq& request, - DeleteBucketLifecycleResp* response); + CosResult DeleteBucketLifecycle(const DeleteBucketLifecycleReq& req, + DeleteBucketLifecycleResp* resp); /// \brief 列出Bucket下的ACL /// @@ -179,8 +177,7 @@ class CosAPI { /// \param resp GetBucketACL返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketACL(const GetBucketACLReq& request, - GetBucketACLResp* response); + CosResult GetBucketACL(const GetBucketACLReq& req, GetBucketACLResp* resp); /// \brief 增加/替换Bucket下的ACL, 可以通过Header或者Body传入ACL信息 /// 注意Header 和 Body 只能选择其中一种,否则响应返回会冲突 @@ -189,8 +186,7 @@ class CosAPI { /// \param resp PutBucketACL返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketACL(const PutBucketACLReq& request, - PutBucketACLResp* response); + CosResult PutBucketACL(const PutBucketACLReq& req, PutBucketACLResp* resp); /// \brief 列出Bucket下的CORS /// @@ -198,8 +194,7 @@ class CosAPI { /// \param resp GetBucketCORS返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketCORS(const GetBucketCORSReq& request, - GetBucketCORSResp* response); + CosResult GetBucketCORS(const GetBucketCORSReq& req, GetBucketCORSResp* resp); /// \brief 增加/替换Bucket下的CORS /// @@ -207,8 +202,7 @@ class CosAPI { /// \param resp PutBucketCORS返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketCORS(const PutBucketCORSReq& request, - PutBucketCORSResp* response); + CosResult PutBucketCORS(const PutBucketCORSReq& req, PutBucketCORSResp* resp); /// \brief 删除Bucket下的CORS /// @@ -216,8 +210,8 @@ class CosAPI { /// \param resp DeleteBucketCORS返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteBucketCORS(const DeleteBucketCORSReq& request, - DeleteBucketCORSResp* response); + CosResult DeleteBucketCORS(const DeleteBucketCORSReq& req, + DeleteBucketCORSResp* resp); /// \brief 为存储桶设置 Referer 白名单或者黑名单 /// @@ -225,8 +219,8 @@ class CosAPI { /// \param resp PutBucketReferer响应 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketReferer(const PutBucketRefererReq& request, - PutBucketRefererResp* response); + CosResult PutBucketReferer(const PutBucketRefererReq& req, + PutBucketRefererResp* resp); /// \brief 为存储桶设置 Referer 白名单或者黑名单 /// @@ -234,8 +228,8 @@ class CosAPI { /// \param resp GetBucketReferer响应 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketReferer(const GetBucketRefererReq& request, - GetBucketRefererResp* response); + CosResult GetBucketReferer(const GetBucketRefererReq& req, + GetBucketRefererResp* resp); /// \brief 设置源存储桶的日志配置信息。 /// /// \param req PutBucketLogging请求 @@ -243,8 +237,8 @@ class CosAPI { /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketLogging(const PutBucketLoggingReq& request, - PutBucketLoggingResp* response); + CosResult PutBucketLogging(const PutBucketLoggingReq& req, + PutBucketLoggingResp* resp); /// \brief 获取源存储桶的日志配置信息。 /// @@ -252,8 +246,8 @@ class CosAPI { /// \param resp GetBucketLogging返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketLogging(const GetBucketLoggingReq& request, - GetBucketLoggingResp* response); + CosResult GetBucketLogging(const GetBucketLoggingReq& req, + GetBucketLoggingResp* resp); /// \brief 设置存储桶自定义域名。 /// @@ -261,8 +255,8 @@ class CosAPI { /// \param resp PutBucketDomain返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketDomain(const PutBucketDomainReq& request, - PutBucketDomainResp* response); + CosResult PutBucketDomain(const PutBucketDomainReq& req, + PutBucketDomainResp* resp); /// \brief 获取存储桶自定义域名。 /// @@ -270,8 +264,8 @@ class CosAPI { /// \param resp GetBucketDomain返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketDomain(const GetBucketDomainReq& request, - GetBucketDomainResp* response); + CosResult GetBucketDomain(const GetBucketDomainReq& req, + GetBucketDomainResp* resp); /// \brief 为存储桶配置静态网站,可以通过传入 XML /// 格式的配置文件进行配置,文件大小限制为64KB. @@ -280,8 +274,8 @@ class CosAPI { /// \param resp PutBucketWebsite返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketWebsite(const PutBucketWebsiteReq& request, - PutBucketWebsiteResp* response); + CosResult PutBucketWebsite(const PutBucketWebsiteReq& req, + PutBucketWebsiteResp* resp); /// \brief 请求用于获取与存储桶关联的静态网站配置信息. /// @@ -289,8 +283,8 @@ class CosAPI { /// \param resp GetBucketWebsite返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketWebsite(const GetBucketWebsiteReq& request, - GetBucketWebsiteResp* response); + CosResult GetBucketWebsite(const GetBucketWebsiteReq& req, + GetBucketWebsiteResp* resp); /// \brief 删除存储桶中的静态网站配置. /// @@ -298,8 +292,8 @@ class CosAPI { /// \param resp DeleteBucketWebsite返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteBucketWebsite(const DeleteBucketWebsiteReq& request, - DeleteBucketWebsiteResp* response); + CosResult DeleteBucketWebsite(const DeleteBucketWebsiteReq& req, + DeleteBucketWebsiteResp* resp); /// \brief 已存在的Bucket设置标签. /// @@ -307,8 +301,8 @@ class CosAPI { /// \param resp PutBucketTagging返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketTagging(const PutBucketTaggingReq& request, - PutBucketTaggingResp* response); + CosResult PutBucketTagging(const PutBucketTaggingReq& req, + PutBucketTaggingResp* resp); /// \brief 查询指定存储桶下已有的存储桶标签. /// @@ -316,8 +310,8 @@ class CosAPI { /// \param resp GetBucketTagging返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketTagging(const GetBucketTaggingReq& request, - GetBucketTaggingResp* response); + CosResult GetBucketTagging(const GetBucketTaggingReq& req, + GetBucketTaggingResp* resp); /// \brief 删除指定存储桶下已有的存储桶标签. /// @@ -325,8 +319,8 @@ class CosAPI { /// \param resp DeleteBucketTagging返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteBucketTagging(const DeleteBucketTaggingReq& request, - DeleteBucketTaggingResp* response); + CosResult DeleteBucketTagging(const DeleteBucketTaggingReq& req, + DeleteBucketTaggingResp* resp); /// \brief 在存储桶中创建清单任务. /// @@ -334,8 +328,8 @@ class CosAPI { /// \param resp PutBucketInventory返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketInventory(const PutBucketInventoryReq& request, - PutBucketInventoryResp* response); + CosResult PutBucketInventory(const PutBucketInventoryReq& req, + PutBucketInventoryResp* resp); /// \brief 用于查询存储桶中用户的清单任务信息. /// @@ -343,8 +337,8 @@ class CosAPI { /// \param resp GetBucketInventory返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketInventory(const GetBucketInventoryReq& request, - GetBucketInventoryResp* response); + CosResult GetBucketInventory(const GetBucketInventoryReq& req, + GetBucketInventoryResp* resp); /// \brief 用于请求返回一个存储桶中的所有清单任务. /// @@ -353,8 +347,8 @@ class CosAPI { /// /// \return 本次请求的调用情况(如状态码等) CosResult ListBucketInventoryConfigurations( - const ListBucketInventoryConfigurationsReq& request, - ListBucketInventoryConfigurationsResp* response); + const ListBucketInventoryConfigurationsReq& req, + ListBucketInventoryConfigurationsResp* resp); /// \brief 用于删除存储桶中指定的清单任务. /// @@ -362,37 +356,36 @@ class CosAPI { /// \param resp DeleteBucketinventory返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteBucketInventory(const DeleteBucketInventoryReq& request, - DeleteBucketInventoryResp* response); + CosResult DeleteBucketInventory(const DeleteBucketInventoryReq& req, + DeleteBucketInventoryResp* resp); /// \brief 获取对应Object的meta信息数据 /// 详见: https://www.qcloud.com/document/product/436/7745 /// - /// \param request HeadObject请求 - /// \param response HeadObject返回 + /// \param req HeadObject请求 + /// \param resp HeadObject返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult HeadObject(const HeadObjectReq& request, HeadObjectResp* response); + CosResult HeadObject(const HeadObjectReq& req, HeadObjectResp* resp); /// \brief 下载Bucket中的一个文件至流中 /// 详见: https://www.qcloud.com/document/product/436/7753 /// - /// \param request GetObjectByStream请求 - /// \param response GetObjectByStream返回 + /// \param req GetObjectByStream请求 + /// \param resp GetObjectByStream返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult GetObject(const GetObjectByStreamReq& request, - GetObjectByStreamResp* response); + CosResult GetObject(const GetObjectByStreamReq& req, + GetObjectByStreamResp* resp); /// \brief 下载Bucket中的一个文件到本地 /// 详见: https://www.qcloud.com/document/product/436/7753 /// - /// \param request GetObjectByFile请求 - /// \param response GetObjectByFile返回 + /// \param req GetObjectByFile请求 + /// \param resp GetObjectByFile返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult GetObject(const GetObjectByFileReq& request, - GetObjectByFileResp* response); + CosResult GetObject(const GetObjectByFileReq& req, GetObjectByFileResp* resp); /// \brief 返回对象的URL /// @@ -408,22 +401,21 @@ class CosAPI { /// \brief 将本地的文件上传至指定Bucket中 /// 详见: https://www.qcloud.com/document/product/436/7749 /// - /// \param request PutObject请求 - /// \param response PutObject返回 + /// \param req PutObject请求 + /// \param resp PutObject返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult PutObject(const PutObjectByFileReq& request, - PutObjectByFileResp* response); + CosResult PutObject(const PutObjectByFileReq& req, PutObjectByFileResp* resp); /// \brief 将指定流上传至指定Bucket中 /// 详见: https://www.qcloud.com/document/product/436/7749 /// - /// \param request PutObject请求 - /// \param response PutObject返回 + /// \param req PutObject请求 + /// \param resp PutObject返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult PutObject(const PutObjectByStreamReq& request, - PutObjectByStreamResp* response); + CosResult PutObject(const PutObjectByStreamReq& req, + PutObjectByStreamResp* resp); /// \brief 删除Object /// 详见: https://cloud.tencent.com/document/product/436/7743 @@ -432,8 +424,7 @@ class CosAPI { /// \param resp DeleteObject返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteObject(const DeleteObjectReq& request, - DeleteObjectResp* response); + CosResult DeleteObject(const DeleteObjectReq& req, DeleteObjectResp* resp); /// \brief 批量删除Object /// @@ -441,62 +432,62 @@ class CosAPI { /// \param resp DeleteObjects返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteObjects(const DeleteObjectsReq& request, - DeleteObjectsResp* response); + CosResult DeleteObjects(const DeleteObjectsReq& req, DeleteObjectsResp* resp); /// \brief /// 请求实现初始化分片上传,成功执行此请求以后会返回UploadId用于后续的Upload /// Part请求 /// 详见: https://www.qcloud.com/document/product/436/7746 /// - /// \param request InitMultiUpload请求 - /// \param response InitMultiUpload返回 + /// \param req InitMultiUpload请求 + /// \param resp InitMultiUpload返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult InitMultiUpload(const InitMultiUploadReq& request, - InitMultiUploadResp* response); + CosResult InitMultiUpload(const InitMultiUploadReq& req, + InitMultiUploadResp* resp); - /// \brief 初始化以后的分片上传,支持的分片的数量为1到10000,片的大小为1MB到5GB + /// \brief + /// 初始化以后的分片上传,支持的分片的数量为1到10000,片的大小为1MB到5GB /// 详见: https://www.qcloud.com/document/product/436/7750 /// - /// \param request UploadPartData请求 - /// \param response UploadPartData返回 + /// \param req UploadPartData请求 + /// \param resp UploadPartData返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult UploadPartData(const UploadPartDataReq& request, - UploadPartDataResp* response); + CosResult UploadPartData(const UploadPartDataReq& req, + UploadPartDataResp* resp); /// \brief /// 初始化以后的分片上传复制,支持的片的数量为1到10000,片的大小为1MB到5GB /// 详见: https://cloud.tencent.com/document/product/436/8287 /// - /// \param request UploadPartCopyData请求 - /// \param response UploadPartCopyData返回 + /// \param req UploadPartCopyData请求 + /// \param resp UploadPartCopyData返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult UploadPartCopyData(const UploadPartCopyDataReq& request, - UploadPartCopyDataResp* response); + CosResult UploadPartCopyData(const UploadPartCopyDataReq& req, + UploadPartCopyDataResp* resp); /// \brief 完成整个分块上传。当使用 Upload Parts 上传完所有块以后, /// 必须调用该 API 来完成整个文件的分块上传 /// 详见: https://www.qcloud.com/document/product/436/7742 /// - /// \param request CompleteMultiUpload请求 - /// \param response CompleteMultiUpload返回 + /// \param req CompleteMultiUpload请求 + /// \param resp CompleteMultiUpload返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult CompleteMultiUpload(const CompleteMultiUploadReq& request, - CompleteMultiUploadResp* response); + CosResult CompleteMultiUpload(const CompleteMultiUploadReq& req, + CompleteMultiUploadResp* resp); /// \brief 舍弃一个分块上传并删除已上传的块 /// 详见: https://www.qcloud.com/document/product/436/7740 /// - /// \param request AbortMultiUpload请求 - /// \param response AbortMultiUpload返回 + /// \param req AbortMultiUpload请求 + /// \param resp AbortMultiUpload返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult AbortMultiUpload(const AbortMultiUploadReq& request, - AbortMultiUploadResp* response); + CosResult AbortMultiUpload(const AbortMultiUploadReq& req, + AbortMultiUploadResp* resp); /// \brief 查询特定分块上传中的已上传的块 /// @@ -504,7 +495,7 @@ class CosAPI { /// \param resp ListParts返回 /// /// \return - CosResult ListParts(const ListPartsReq& request, ListPartsResp* response); + CosResult ListParts(const ListPartsReq& req, ListPartsResp* resp); /// \brief 列出Object下的ACL /// @@ -512,8 +503,7 @@ class CosAPI { /// \param resp GetObjectACL返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetObjectACL(const GetObjectACLReq& request, - GetObjectACLResp* response); + CosResult GetObjectACL(const GetObjectACLReq& req, GetObjectACLResp* resp); /// \brief 增加/替换Object下的ACL, 可以通过Header或者Body传入ACL信息 /// 注意Header 和 Body 只能选择其中一种,否则响应返回会冲突 @@ -522,8 +512,7 @@ class CosAPI { /// \param resp PutObjectACL返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutObjectACL(const PutObjectACLReq& request, - PutObjectACLResp* response); + CosResult PutObjectACL(const PutObjectACLReq& req, PutObjectACLResp* resp); /// \brief 复制Object, 适用于跨园区且Object小于5G /// @@ -531,8 +520,7 @@ class CosAPI { /// \param resp PutObjectCopy返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutObjectCopy(const PutObjectCopyReq& request, - PutObjectCopyResp* response); + CosResult PutObjectCopy(const PutObjectCopyReq& req, PutObjectCopyResp* resp); /// \brief 复制Object, /// 自动判断源Object大小,调用PutObjectCopy/UploadPartCopyData @@ -541,16 +529,16 @@ class CosAPI { /// \param resp Copy返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult Copy(const CopyReq& request, CopyResp* response); + CosResult Copy(const CopyReq& req, CopyResp* resp); /// \brief 对一个通过 COS 归档为 archive 类型的对象进行恢复 /// - /// \param request PostObjectRestore请求 - /// \param response PostObjectRestore返回 + /// \param req PostObjectRestore请求 + /// \param resp PostObjectRestore返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult PostObjectRestore(const PostObjectRestoreReq& request, - PostObjectRestoreResp* response); + CosResult PostObjectRestore(const PostObjectRestoreReq& req, + PostObjectRestoreResp* resp); /// \brief /// 实现Object跨域访问请求的预请求,参考https://cloud.tencent.com/document/product/436/8288 @@ -559,13 +547,12 @@ class CosAPI { /// \param resp OptionsObjectResp 响应 /// /// \return 本次请求的调用情况(如状态码等) - CosResult OptionsObject(const OptionsObjectReq& request, - OptionsObjectResp* response); + CosResult OptionsObject(const OptionsObjectReq& req, OptionsObjectResp* resp); /// \brief 支持SELECT /// 接口,参考https://cloud.tencent.com/document/product/436/37641 - CosResult SelectObjectContent(const SelectObjectContentReq& request, - SelectObjectContentResp* response); + CosResult SelectObjectContent(const SelectObjectContentReq& req, + SelectObjectContentResp* resp); /// \brief 追加对象, 参考https://cloud.tencent.com/document/product/436/7743 /// @@ -573,8 +560,7 @@ class CosAPI { /// \param resp AppendObject返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult AppendObject(const AppendObjectReq& request, - AppendObjectResp* response); + CosResult AppendObject(const AppendObjectReq& req, AppendObjectResp* resp); /// \brief 列出Bucket下的部分或者全部Object(包括多版本) /// @@ -582,8 +568,8 @@ class CosAPI { /// \param resp GetBucketObjectVersions返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketObjectVersions(const GetBucketObjectVersionsReq& request, - GetBucketObjectVersionsResp* response); + CosResult GetBucketObjectVersions(const GetBucketObjectVersionsReq& req, + GetBucketObjectVersionsResp* resp); /// \brief 创建推流通道 /// @@ -591,8 +577,8 @@ class CosAPI { /// \param resp PutLiveChannelResp返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutLiveChannel(const PutLiveChannelReq& request, - PutLiveChannelResp* response); + CosResult PutLiveChannel(const PutLiveChannelReq& req, + PutLiveChannelResp* resp); /// \brief 生成推流通道带签名的推流url /// @@ -602,9 +588,10 @@ class CosAPI { /// \param url_params url参数 /// /// \return 带签名的推流url - std::string GetRtmpSignedPublishUrl( - const std::string& bucket, const std::string& channel, int expire, - const std::map url_params); + std::string + GetRtmpSignedPublishUrl(const std::string& bucket, const std::string& channel, + int expire, + const std::map url_params); /// \brief 启用或者禁用直播通道 /// @@ -612,8 +599,8 @@ class CosAPI { /// \param resp PutLiveChannelSwitchResp返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutLiveChannelSwitch(const PutLiveChannelSwitchReq& request, - PutLiveChannelSwitchResp* response); + CosResult PutLiveChannelSwitch(const PutLiveChannelSwitchReq& req, + PutLiveChannelSwitchResp* resp); /// \brief 获取直播通道配置信息 /// @@ -621,8 +608,8 @@ class CosAPI { /// \param resp GetLiveChannelResp返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetLiveChannel(const GetLiveChannelReq& request, - GetLiveChannelResp* response); + CosResult GetLiveChannel(const GetLiveChannelReq& req, + GetLiveChannelResp* resp); /// \brief 获取直播通道推流历史 /// @@ -630,8 +617,8 @@ class CosAPI { /// \param resp GetLiveChannelHistoryResp返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetLiveChannelHistory(const GetLiveChannelHistoryReq& request, - GetLiveChannelHistoryResp* response); + CosResult GetLiveChannelHistory(const GetLiveChannelHistoryReq& req, + GetLiveChannelHistoryResp* resp); /// \brief 获取直播通道推流状态 /// @@ -639,8 +626,8 @@ class CosAPI { /// \param resp GetLiveChannelStatusResp返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetLiveChannelStatus(const GetLiveChannelStatusReq& request, - GetLiveChannelStatusResp* response); + CosResult GetLiveChannelStatus(const GetLiveChannelStatusReq& req, + GetLiveChannelStatusResp* resp); /// \brief 删除直播通道 /// @@ -648,8 +635,8 @@ class CosAPI { /// \param resp GetLiveChannelStatusResp返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteLiveChannel(const DeleteLiveChannelReq& request, - DeleteLiveChannelResp* response); + CosResult DeleteLiveChannel(const DeleteLiveChannelReq& req, + DeleteLiveChannelResp* resp); /// \brief 查询指定通道在指定时间段推流生成的播放列表 /// @@ -657,9 +644,8 @@ class CosAPI { /// \param resp GetLiveChannelVodPlaylistResp返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetLiveChannelVodPlaylist( - const GetLiveChannelVodPlaylistReq& request, - GetLiveChannelVodPlaylistResp* response); + CosResult GetLiveChannelVodPlaylist(const GetLiveChannelVodPlaylistReq& req, + GetLiveChannelVodPlaylistResp* resp); /// \brief 为指定通道生成一个可供点播例用的播放列 /// @@ -667,9 +653,8 @@ class CosAPI { /// \param resp PostLiveChannelVodPlaylistResp返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PostLiveChannelVodPlaylist( - const PostLiveChannelVodPlaylistReq& request, - PostLiveChannelVodPlaylistResp* response); + CosResult PostLiveChannelVodPlaylist(const PostLiveChannelVodPlaylistReq& req, + PostLiveChannelVodPlaylistResp* resp); /// \brief 列举通道 /// @@ -677,8 +662,8 @@ class CosAPI { /// \param resp PostLiveChannelVodPlaylistResp返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult ListLiveChannel(const ListLiveChannelReq& request, - ListLiveChannelResp* response); + CosResult ListLiveChannel(const ListLiveChannelReq& req, + ListLiveChannelResp* resp); /// \brief 配置存储桶智能分层 /// @@ -686,9 +671,9 @@ class CosAPI { /// \param resp PutBucketIntelligentTiering返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult PutBucketIntelligentTiering( - const PutBucketIntelligentTieringReq& request, - PutBucketIntelligentTieringResp* response); + CosResult + PutBucketIntelligentTiering(const PutBucketIntelligentTieringReq& req, + PutBucketIntelligentTieringResp* resp); /// \brief 获取存储桶智能分层配置 /// @@ -696,86 +681,90 @@ class CosAPI { /// \param resp GetBucketIntelligentTiering返回 /// /// \return 本次请求的调用情况(如状态码等) - CosResult GetBucketIntelligentTiering( - const GetBucketIntelligentTieringReq& request, - GetBucketIntelligentTieringResp* response); + CosResult + GetBucketIntelligentTiering(const GetBucketIntelligentTieringReq& req, + GetBucketIntelligentTieringResp* resp); /*Multithread接口*/ /// \brief 封装了初始化分块上传、分块上传、完成分块上传三步,支持断点续传 /// - /// \param request MultiUploadObject请求 - /// \param response MultiUploadObject返回 + /// \param req MultiUploadObject请求 + /// \param resp MultiUploadObject返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult MultiUploadObject(const MultiUploadObjectReq& request, - MultiUploadObjectResp* response); + CosResult PutObject(const MultiPutObjectReq& req, MultiPutObjectResp* resp); /// \brief 多线程Range下载Bucket中的一个文件到本地 /// 详见: https://www.qcloud.com/document/product/436/7753 /// - /// \param request MultiGetObject请求 - /// \param response MultiGetObject返回 + /// \param req MultiGetObject请求 + /// \param resp MultiGetObject返回 /// /// \return 返回HTTP请求的状态码及错误信息 - CosResult GetObject(const MultiGetObjectReq& request, - MultiGetObjectResp* response); + CosResult GetObject(const MultiGetObjectReq& req, MultiGetObjectResp* resp); /*Resumable接口*/ /// \brief 封装了初始化分块上传、分块上传、完成分块上传三步,支持断点续传 - // CosResult ResumablePutObject(const MultiUploadObjectReq& request, - // MultiUploadObjectResp* response); + // CosResult ResumablePutObject(const MultiPutObjectReq& req, + // MultiPutObjectResp* resp); /// \brief 支持断点下载 - CosResult ResumableGetObject(const MultiGetObjectReq& request, - MultiGetObjectResp* response); + CosResult ResumableGetObject(const MultiGetObjectReq& req, + MultiGetObjectResp* resp); /*Async接口*/ + /// \brief 异步简单上传 + /// \param req PutObjectByFileReq请求 + /// \return 返回context + //SharedAsyncContext PutObjectAsync(const PutObjectByFileReq& req); + /// \brief /// 异步上传对象,封装了初始化分块上传、分块上传、完成分块上传三步,支持断点续传 - /// \param request MultiUploadObject请求 - /// \param response MultiUploadObject返回 - /// \return 返回handler - SharedTransferHandler PutObjectAsync(const MultiUploadObjectReq& request, - MultiUploadObjectResp* response); - - /// \brief 异步多线程下载对象,支持更新下载进度 - /// \param request MultiGetObject请求 - /// \param response MultiGetObject返回 - /// \return 返回handler - SharedTransferHandler GetObjectAsync(const MultiGetObjectReq& request, - MultiGetObjectResp* response); + /// \param req MultiUploadObject请求 + /// \return 返回context + SharedAsyncContext PutObjectAsync(const MultiPutObjectReq& req); + + /// \brief 异步单线程下载对象 + /// \param req GetObjectByFileReq请求 + /// \return 返回context + //SharedAsyncContext GetObjectAsync(const GetObjectByFileReq& req); + + /// \brief 异步多线程下载对象 + /// \param req MultiGetObject请求 + /// \param resp MultiGetObject返回 + /// \return 返回context + SharedAsyncContext GetObjectAsync(const MultiGetObjectReq& req); /*批量及目录操作接口*/ /// \brief 批量上传对象 - /// \param request PutObjectsByDirectory请求 - /// \param response PutObjectByDirectoryResp返回 + /// \param req PutObjectsByDirectory请求 + /// \param resp PutObjectByDirectoryResp返回 /// \return 批量上传结果 - CosResult PutObjects(const PutObjectsByDirectoryReq& request, - PutObjectsByDirectoryResp* response); + CosResult PutObjects(const PutObjectsByDirectoryReq& req, + PutObjectsByDirectoryResp* resp); /// \brief 创建目录 - /// \param request PutObjectsByDirectory请求 - /// \param response PutObjectByDirectoryResp返回 + /// \param req PutObjectsByDirectory请求 + /// \param resp PutObjectByDirectoryResp返回 /// \return 创建目录结果 - CosResult PutDirectory(const PutDirectoryReq& request, - PutDirectoryResp* response); + CosResult PutDirectory(const PutDirectoryReq& req, PutDirectoryResp* resp); /// \brief 移动对象 - /// \param request MoveObjectReq请求 - /// \param response MoveObjectResp返回 + /// \param req MoveObjectReq请求 + /// \param resp MoveObjectResp返回 /// \return 移动对象结果 - CosResult MoveObject(const MoveObjectReq& request, MoveObjectResp* response); + CosResult MoveObject(const MoveObjectReq& req, MoveObjectResp* resp); /// \brief 按前缀删除Object /// \param req DeleteObjectsByPrefixReq请求 /// \param resp DeleteObjectsByPrefixResp返回 /// \return 本次请求的调用情况(如状态码等) - CosResult DeleteObjects(const DeleteObjectsByPrefixReq& request, - DeleteObjectsByPrefixResp* response); + CosResult DeleteObjects(const DeleteObjectsByPrefixReq& req, + DeleteObjectsByPrefixResp* resp); /*数据处理接口*/ @@ -784,69 +773,65 @@ class CosAPI { /**图片持久化处理**/ /***上传时处理***/ - CosResult PutImage(const PutImageByFileReq& request, - PutImageByFileResp* response); + CosResult PutImage(const PutImageByFileReq& req, PutImageByFileResp* resp); /***云上数据处理***/ - CosResult CloudImageProcess(const CloudImageProcessReq& request, - CloudImageProcessResp* response); + CosResult CloudImageProcess(const CloudImageProcessReq& req, + CloudImageProcessResp* resp); /***下载图片时识别二维码***/ - CosResult GetQRcode(const GetQRcodeReq& request, GetQRcodeResp* response); + CosResult GetQRcode(const GetQRcodeReq& req, GetQRcodeResp* resp); /**文档处理接口**/ /***查询已经开通文档预览功能的 Bucket***/ // https://cloud.tencent.com/document/product/436/54057 - CosResult DescribeDocProcessBuckets( - const DescribeDocProcessBucketsReq& request, - DescribeDocProcessBucketsResp* response); + CosResult DescribeDocProcessBuckets(const DescribeDocProcessBucketsReq& req, + DescribeDocProcessBucketsResp* resp); /***预览文档***/ // https://cloud.tencent.com/document/product/436/54058 - CosResult DocPreview(const DocPreviewReq& request, DocPreviewResp* response); + CosResult DocPreview(const DocPreviewReq& req, DocPreviewResp* resp); /***提交一个文档预览任务***/ // https://cloud.tencent.com/document/product/436/54056 - CosResult CreateDocProcessJobs(const CreateDocProcessJobsReq& request, - CreateDocProcessJobsResp* response); + CosResult CreateDocProcessJobs(const CreateDocProcessJobsReq& req, + CreateDocProcessJobsResp* resp); /***查询指定的文档预览任务***/ // https://cloud.tencent.com/document/product/436/54095 - CosResult DescribeDocProcessJob(const DescribeDocProcessJobReq& request, - DescribeDocProcessJobResp* response); + CosResult DescribeDocProcessJob(const DescribeDocProcessJobReq& req, + DescribeDocProcessJobResp* resp); /***拉取符合条件的文档预览任务***/ // https://cloud.tencent.com/document/product/436/54096 - CosResult DescribeDocProcessJobs(const DescribeDocProcessJobsReq& request, - DescribeDocProcessJobsResp* response); + CosResult DescribeDocProcessJobs(const DescribeDocProcessJobsReq& req, + DescribeDocProcessJobsResp* resp); /***查询文档预览队列***/ // https://cloud.tencent.com/document/product/436/54055 - CosResult DescribeDocProcessQueues(const DescribeDocProcessQueuesReq& request, - DescribeDocProcessQueuesResp* response); + CosResult DescribeDocProcessQueues(const DescribeDocProcessQueuesReq& req, + DescribeDocProcessQueuesResp* resp); /***更新文档预览队列***/ // https://cloud.tencent.com/document/product/436/54094 - CosResult UpdateDocProcessQueue(const UpdateDocProcessQueueReq& request, - UpdateDocProcessQueueResp* response); + CosResult UpdateDocProcessQueue(const UpdateDocProcessQueueReq& req, + UpdateDocProcessQueueResp* resp); /**媒体处理接口**/ /***查询已经开通媒体处理功能的存储桶***/ // https://cloud.tencent.com/document/product/436/48988 - CosResult DescribeMediaBuckets(const DescribeMediaBucketsReq& request, - DescribeMediaBucketsResp* response); + CosResult DescribeMediaBuckets(const DescribeMediaBucketsReq& req, + DescribeMediaBucketsResp* resp); /***获取媒体文件某个时间的截图***/ // https://cloud.tencent.com/document/product/436/55671 - CosResult GetSnapshot(const GetSnapshotReq& request, - GetSnapshotResp* response); + CosResult GetSnapshot(const GetSnapshotReq& req, GetSnapshotResp* resp); /***获取媒体文件的信息***/ // https://cloud.tencent.com/document/product/436/55672 - CosResult GetMediaInfo(const GetMediaInfoReq& request, - GetMediaInfoResp* response); + CosResult GetMediaInfo(const GetMediaInfoReq& req, GetMediaInfoResp* resp); private: int CosInit(); diff --git a/include/cos_defines.h b/include/cos_defines.h index 54cefac..75328b7 100644 --- a/include/cos_defines.h +++ b/include/cos_defines.h @@ -11,7 +11,7 @@ namespace qcloud_cos { -#define COS_CPP_SDK_VERSON "v5.5.1" +#define COS_CPP_SDK_VERSON "v5.5.3" /// 路径分隔符 const std::string kPathDelimiter = "/"; diff --git a/include/cos_sys_config.h b/include/cos_sys_config.h index d4a8e13..d19e26c 100644 --- a/include/cos_sys_config.h +++ b/include/cos_sys_config.h @@ -205,5 +205,6 @@ class CosSysConfig { // dns cache大小 static unsigned m_dns_cache_size; }; + } // namespace qcloud_cos #endif diff --git a/include/op/cos_result.h b/include/op/cos_result.h index 0f5f5af..9d92328 100644 --- a/include/op/cos_result.h +++ b/include/op/cos_result.h @@ -21,7 +21,6 @@ class CosResult { CosResult() : m_is_succ(false), m_http_status(-1), - m_error_info(""), m_err_code(""), m_err_msg(""), m_resource_addr(""), @@ -33,7 +32,6 @@ class CosResult { CosResult(const CosResult& other) { m_is_succ = other.m_is_succ; m_http_status = other.m_http_status; - m_error_info = other.m_error_info; m_err_code = other.m_err_code; m_err_msg = other.m_err_msg; m_resource_addr = other.m_resource_addr; @@ -46,7 +44,6 @@ class CosResult { if (this != &other) { m_is_succ = other.m_is_succ; m_http_status = other.m_http_status; - m_error_info = other.m_error_info; m_err_code = other.m_err_code; m_err_msg = other.m_err_msg; m_resource_addr = other.m_resource_addr; @@ -63,7 +60,6 @@ class CosResult { void Clear() { m_is_succ = false; m_http_status = -1; - m_error_info = ""; m_err_code = ""; m_err_msg = ""; m_resource_addr = ""; @@ -76,7 +72,6 @@ class CosResult { const std::string& body); // Getter - std::string GetErrorInfo() const { return m_error_info; } int GetHttpStatus() const { return m_http_status; } std::string GetErrorCode() const { return m_err_code; } std::string GetErrorMsg() const { return m_err_msg; } @@ -87,7 +82,6 @@ class CosResult { uint64_t GetRealByte() const { return m_real_byte; } // Setter - void SetErrorInfo(const std::string& result) { m_error_info = result; } void SetHttpStatus(int http_status) { m_http_status = http_status; } void SetErrorCode(const std::string& err_code) { m_err_code = err_code; } void SetErrorMsg(const std::string& err_msg) { m_err_msg = err_msg; } @@ -113,10 +107,7 @@ class CosResult { private: bool m_is_succ; // 标识HTTP调用是否成功 - int m_http_status; // http状态码 - std::string m_error_info; // 错误的具体信息, - // 存放sdk内部错误/调用失败时无法解析的返回信息 - + int m_http_status; // http状态码 // COS返回的错误信息 std::string m_err_code; std::string m_err_msg; diff --git a/include/op/object_op.h b/include/op/object_op.h index 61623ba..dedf1cf 100644 --- a/include/op/object_op.h +++ b/include/op/object_op.h @@ -7,7 +7,6 @@ #ifndef OBJECT_OP_H #define OBJECT_OP_H -#pragma once #include "op/base_op.h" #include "op/cos_result.h" @@ -40,13 +39,13 @@ class ObjectOp : public BaseOp { std::string GetResumableUploadID(const std::string& bucket_name, const std::string& object_name); - bool CheckUploadPart(const MultiUploadObjectReq& req, + bool CheckUploadPart(const MultiPutObjectReq& req, const std::string& bucket_name, const std::string& object_name, const std::string& uploadid, std::vector& already_exist); - bool CheckSinglePart(const MultiUploadObjectReq& req, uint64_t offset, + bool CheckSinglePart(const MultiPutObjectReq& req, uint64_t offset, uint64_t local_part_size, uint64_t size, const std::string& etag); @@ -164,8 +163,8 @@ class ObjectOp : public BaseOp { /// \param handler TransferHandler /// /// \return result - CosResult MultiUploadObject(const MultiUploadObjectReq& req, - MultiUploadObjectResp* resp, + CosResult MultiUploadObject(const MultiPutObjectReq& req, + MultiPutObjectResp* resp, const SharedTransferHandler& handler = nullptr); /// \brief 舍弃一个分块上传并删除已上传的块 @@ -363,12 +362,12 @@ class ObjectOp : public BaseOp { std::string* req_body); /// \brief 多线程上传,handler处理回调 - CosResult MultiThreadUpload( - const MultiUploadObjectReq& req, const std::string& upload_id, - const std::vector& already_exist_parts, bool resume_flag, - std::vector* etags_ptr, - std::vector* part_numbers_ptr, - const SharedTransferHandler& handler = nullptr); + CosResult + MultiThreadUpload(const MultiPutObjectReq& req, const std::string& upload_id, + const std::vector& already_exist_parts, + bool resume_flag, std::vector* etags_ptr, + std::vector* part_numbers_ptr, + const SharedTransferHandler& handler = nullptr); /// \brief 读取文件内容, 并返回读取的长度 uint64_t GetContent(const std::string& src, std::string* file_content) const; @@ -386,7 +385,7 @@ class ObjectOp : public BaseOp { FileCopyTask* task); /// \brief 检查是否可以走断点下载 - /// \param req MultiUploadObjectReq请求 + /// \param req MultiPutObjectReq请求 /// \param head_resp HeadObjectResp响应结果 /// \param last_offset 返回的上一次下载偏移量 /// \return true可以走断点下载,false表示不可以 @@ -403,6 +402,7 @@ class ObjectOp : public BaseOp { const std::string& json_file, const std::map& element_map, uint64_t resume_offset); + void SetResultAndLogError(CosResult& result, const std::string& err_msg); }; } // namespace qcloud_cos diff --git a/include/request/object_req.h b/include/request/object_req.h index 312c977..59aa047 100644 --- a/include/request/object_req.h +++ b/include/request/object_req.h @@ -14,7 +14,7 @@ #endif #include "cos_sys_config.h" #include "request/base_req.h" -#include "trsf/transfer_handler.h" +#include "trsf/async_context.h" namespace qcloud_cos { @@ -23,7 +23,7 @@ class ObjectReq : public BaseReq { ObjectReq(const std::string& bucket_name, const std::string& object_name) : m_bucket_name(bucket_name), m_progress_cb(NULL), - m_status_cb(NULL), + m_done_cb(NULL), m_user_data(NULL) { SetObjectName(object_name); } @@ -48,28 +48,25 @@ class ObjectReq : public BaseReq { } /// @brief 设置进度回调函数 - void SetTransferProgressCallback(TransferProgressCallback callback) { - m_progress_cb = callback; - } - /// @brief 设置状态回调函数 - void SetTransferStatusCallback(TransferStatusCallback callback) { - m_status_cb = callback; + void SetTransferProgressCallback(const TransferProgressCallback& process_cb) { + m_progress_cb = process_cb; } + /// @brief 设置完成回调函数 + void SetDoneCallback(const DoneCallback& done_cb) { m_done_cb = done_cb; } /// @brief 设置回调私有数据 - void SetTransferCallbackUserData(void* user_data) { m_user_data = user_data; } + void SetUserData(void* user_data) { m_user_data = user_data; } + TransferProgressCallback GetTransferProgressCallback() const { return m_progress_cb; } - TransferStatusCallback GetTransferStatusCallback() const { - return m_status_cb; - } - void* GetTransferCallbackUserData() const { return m_user_data; } + DoneCallback GetDoneCallback() const { return m_done_cb; } + void* GetUserData() const { return m_user_data; } private: std::string m_bucket_name; std::string m_object_name; TransferProgressCallback m_progress_cb; // 进度回调 - TransferStatusCallback m_status_cb; // 状态回调 + DoneCallback m_done_cb; // 完成回调 void* m_user_data; // 私有数据 }; @@ -705,11 +702,11 @@ class CompleteMultiUploadReq : public ObjectReq { std::vector m_etags; }; -class MultiUploadObjectReq : public ObjectReq { +class MultiPutObjectReq : public ObjectReq { public: - MultiUploadObjectReq(const std::string& bucket_name, - const std::string& object_name, - const std::string& local_file_path = "") + MultiPutObjectReq(const std::string& bucket_name, + const std::string& object_name, + const std::string& local_file_path = "") : ObjectReq(bucket_name, object_name) #if defined(_WIN32) , @@ -730,7 +727,7 @@ class MultiUploadObjectReq : public ObjectReq { // 分块上传默认检查crc64 SetCheckCRC64(true); } - virtual ~MultiUploadObjectReq() {} + virtual ~MultiPutObjectReq() {} void SetLocalFilePath(const std::string& local_file_path) { m_local_file_path = local_file_path; diff --git a/include/response/base_resp.h b/include/response/base_resp.h index c2e5c66..e726802 100644 --- a/include/response/base_resp.h +++ b/include/response/base_resp.h @@ -26,6 +26,16 @@ class BaseResp { public: BaseResp() : m_x_cos_storage_class(kStorageClassStandard), m_content_length(0) {} + + BaseResp(const BaseResp& rhs) { InternalCopyFrom(rhs); } + + BaseResp& operator=(const BaseResp& rhs) { + if (&rhs != this) { + InternalCopyFrom(rhs); + } + return *this; + } + virtual ~BaseResp() {} // debug使用 @@ -49,9 +59,10 @@ class BaseResp { // ==========================头部相关============================== // TODO 头部可以不需要解析 - virtual void ParseFromHeaders( - const std::map& headers); + virtual void + ParseFromHeaders(const std::map& headers); uint64_t GetContentLength() const { return m_content_length; } + std::string GetContentRange() const { return m_content_range; } std::string GetContentType() const { return m_content_type; } std::string GetEtag() const { return m_etag; } std::string GetConnection() const { return m_connection; } @@ -92,8 +103,8 @@ class BaseResp { m_cache_control = cache_control; } void SetExpires(const std::string& expires) { m_expires = expires; } - void SetXCosRequestId(const std::string& id) { m_x_cos_request_id = id; } void SetXCosTraceId(const std::string& id) { m_x_cos_trace_id = id; } + void SetXCosRequestId(const std::string& id) { m_x_cos_request_id = id; } void SetXCosStorageTier(const std::string& storage_tier) { m_x_cos_storage_tier = storage_tier; } @@ -128,6 +139,7 @@ class BaseResp { std::string m_body_str; // 公共头部字段 uint64_t m_content_length; + std::string m_content_range; std::string m_content_type; std::string m_etag; std::string m_connection; diff --git a/include/response/object_resp.h b/include/response/object_resp.h index d56b8ad..1e2b0ca 100644 --- a/include/response/object_resp.h +++ b/include/response/object_resp.h @@ -53,6 +53,21 @@ class GetObjectResp : public BaseResp { protected: GetObjectResp() {} + + GetObjectResp(const GetObjectResp& rhs) + : BaseResp(rhs), + m_x_cos_object_type(rhs.m_x_cos_object_type), + m_x_cos_metas(rhs.m_x_cos_metas) {} + + GetObjectResp& operator=(const GetObjectResp& rhs) { + if (&rhs != this) { + BaseResp::operator=(rhs); + m_x_cos_object_type = rhs.m_x_cos_object_type; + m_x_cos_metas = rhs.m_x_cos_metas; + } + return *this; + } + virtual ~GetObjectResp() {} private: @@ -75,6 +90,16 @@ class GetObjectByFileResp : public GetObjectResp { class MultiGetObjectResp : public GetObjectResp { public: MultiGetObjectResp() {} + + MultiGetObjectResp(const MultiGetObjectResp& rhs) : GetObjectResp(rhs) {} + + MultiGetObjectResp& operator=(const MultiGetObjectResp& rhs) { + if (&rhs != this) { + GetObjectResp::operator=(rhs); + } + return *this; + } + virtual ~MultiGetObjectResp() {} /// Server端加密使用的算法 @@ -123,7 +148,7 @@ class DeleteObjectsResp : public BaseResp { std::vector GetDeletedInfos() const { return m_deleted_infos; } - std::vector GetErrorinfos() const { return m_error_infos; } + std::vector GetErrorMsgs() const { return m_error_infos; } virtual bool ParseFromXmlString(const std::string& body); @@ -261,11 +286,13 @@ class CompleteMultiUploadResp : public BaseResp { std::string m_key; }; -class MultiUploadObjectResp : public BaseResp { +class MultiPutObjectResp : public BaseResp { public: - MultiUploadObjectResp() {} + MultiPutObjectResp() {} + + virtual ~MultiPutObjectResp() {} - virtual ~MultiUploadObjectResp() {} + virtual bool ParseFromXmlString(const std::string& body); std::string GetRespTag() { return m_resp_tag; } diff --git a/include/trsf/async_context.h b/include/trsf/async_context.h new file mode 100644 index 0000000..52c3df5 --- /dev/null +++ b/include/trsf/async_context.h @@ -0,0 +1,41 @@ +#pragma once +#include "response/object_resp.h" +#include "trsf/transfer_handler.h" +#include + +namespace qcloud_cos { + +class AsyncContext { + public: + AsyncContext(const SharedTransferHandler& handler) : m_handler(handler) {} + + /// @brief 取消操作 + void Cancel() { return m_handler->Cancel(); } + + /// @brief 等待操作结束 + void WaitUntilFinish() { return m_handler->WaitUntilFinish(); } + + std::string GetBucketName() const { return m_handler->GetBucketName(); } + + std::string GetObjectName() const { return m_handler->GetObjectName(); } + + std::string GetLocalFilePath() const { return m_handler->GetLocalFilePath(); } + + /// @brief 获取操作结果 + CosResult GetResult() const { return m_handler->GetResult(); } + + /// @brief 获取多线程上传响应 + MultiPutObjectResp GetMultiPutObjectResp() const { + return m_handler->GetMultiPutObjectResp(); + } + + /// @brief 获取多线程下载响应 + MultiGetObjectResp GetMultiGetObjectResp() const { + return m_handler->GetMultiGetObjectResp(); + } + + private: + SharedTransferHandler m_handler; +}; + +} // namespace qcloud_cos \ No newline at end of file diff --git a/include/trsf/transfer_handler.h b/include/trsf/transfer_handler.h index 1786b2e..e5d4291 100644 --- a/include/trsf/transfer_handler.h +++ b/include/trsf/transfer_handler.h @@ -1,6 +1,8 @@ #ifndef __TRSF_HANDLER_H__ #define __TRSF_HANDLER_H__ +#include "op/cos_result.h" +#include "response/object_resp.h" #include #include #include @@ -8,17 +10,22 @@ #include #include -#include "op/cos_result.h" - namespace qcloud_cos { +class TransferHandler; +class AsyncContext; + +typedef std::shared_ptr SharedTransferHandler; + +typedef std::shared_ptr SharedAsyncContext; + /// @brief 进度回调函数 -typedef void (*TransferProgressCallback)(uint64_t transferred_size, - uint64_t total_size, void* user_data); +using TransferProgressCallback = std::function; -/// @brief 状态回调函数 -typedef void (*TransferStatusCallback)(const std::string& status, - void* user_data); +/// @brief 完成回调函数 +using DoneCallback = + std::function; class PartState { public: @@ -72,12 +79,12 @@ enum class TransferStatus { }; // For now support the multiupload -class TransferHandler { +class TransferHandler : public std::enable_shared_from_this { public: // Upload TransferHandler(const std::string& bucket_name, - const std::string& object_name, uint64_t total_size, - const std::string& file_path = ""); + const std::string& object_name, const std::string& file_path); + ~TransferHandler() {} void SetBucketName(const std::string& bucket_name) { m_bucket_name = bucket_name; @@ -105,7 +112,11 @@ class TransferHandler { void UpdateStatus(const TransferStatus& status); void UpdateStatus(const TransferStatus& status, const CosResult& result); - // Get the current status of process, detail see the enum TransferStatus. + + void UpdateStatus(const TransferStatus& status, const CosResult& result, + const std::map headers, + const std::string& body = ""); + TransferStatus GetStatus() const; std::string GetStatusString() const; @@ -127,19 +138,30 @@ class TransferHandler { void WaitUntilFinish(); /// @brief 设置进度回调函数 - void SetTransferProgressCallback(TransferProgressCallback callback) { + void SetTransferProgressCallback(const TransferProgressCallback& callback) { m_progress_cb = callback; } /// @brief 设置状态回调函数 - void SetTransferStatusCallback(TransferStatusCallback callback) { - m_status_cb = callback; - } + void SetDoneCallback(const DoneCallback& callback) { m_done_cb = callback; } + /// @brief 设置回调私有数据 - void SetTransferCallbackUserData(void* user_data) { m_user_data = user_data; } + void SetUserData(void* user_data) { m_user_data = user_data; } - public: - // Origin result + /////////////////////////////////////////////////////////////////////////// + // 用户调用的函数 + /// @brief 获取操作结果 + CosResult GetResult() const { return m_result; } + + /// @brief 获取多线程上传响应 + MultiPutObjectResp GetMultiPutObjectResp() const; + + /// @brief 获取多线程下载响应 + MultiGetObjectResp GetMultiGetObjectResp() const; + + private: CosResult m_result; + std::map m_resp_headers; + std::string m_resp_body; private: std::string m_bucket_name; @@ -165,16 +187,13 @@ class TransferHandler { // callback function TransferProgressCallback m_progress_cb; - TransferStatusCallback m_status_cb; + DoneCallback m_done_cb; void* m_user_data; // Mutex lock for the part map // mutable boost::mutex m_lock_parts; }; -/// @异步回调Hanlder -typedef std::shared_ptr SharedTransferHandler; - class HandleStreamCopier { public: static std::streamsize handleCopyStream(const SharedTransferHandler& handler, diff --git a/libs/Win32/cossdk.lib b/libs/Win32/cossdk.lib index e94eef0..286fe4c 100644 Binary files a/libs/Win32/cossdk.lib and b/libs/Win32/cossdk.lib differ diff --git a/libs/linux/libcossdk-shared.so b/libs/linux/libcossdk-shared.so index 93233cf..f64ffaa 100644 Binary files a/libs/linux/libcossdk-shared.so and b/libs/linux/libcossdk-shared.so differ diff --git a/libs/linux/libcossdk.a b/libs/linux/libcossdk.a index bfbfa82..3a41622 100644 Binary files a/libs/linux/libcossdk.a and b/libs/linux/libcossdk.a differ diff --git a/libs/x64/cossdk.lib b/libs/x64/cossdk.lib index f703f3c..ea6801b 100644 Binary files a/libs/x64/cossdk.lib and b/libs/x64/cossdk.lib differ diff --git a/src/cos_api.cpp b/src/cos_api.cpp index c8969e5..fbfda32 100644 --- a/src/cos_api.cpp +++ b/src/cos_api.cpp @@ -1,15 +1,14 @@ #include "cos_api.h" - -#include - #include "Poco/Net/HTTPSStreamFactory.h" #include "Poco/Net/HTTPStreamFactory.h" #include "Poco/Net/SSLManager.h" #include "Poco/TaskManager.h" #include "cos_sys_config.h" +#include "trsf/async_context.h" #include "trsf/async_task.h" #include "util/file_util.h" #include "util/string_util.h" +#include namespace qcloud_cos { @@ -71,9 +70,8 @@ bool CosAPI::IsObjectExist(const std::string& bucket_name, return m_object_op.IsObjectExist(bucket_name, object_name); } -std::string CosAPI::GeneratePresignedUrl( - const GeneratePresignedUrlReq& request) { - return m_object_op.GeneratePresignedUrl(request); +std::string CosAPI::GeneratePresignedUrl(const GeneratePresignedUrlReq& req) { + return m_object_op.GeneratePresignedUrl(req); } std::string CosAPI::GeneratePresignedUrl(const std::string& bucket_name, @@ -100,212 +98,206 @@ std::string CosAPI::GetBucketLocation(const std::string& bucket_name) { return m_bucket_op.GetBucketLocation(bucket_name); } -CosResult CosAPI::GetService(const GetServiceReq& request, - GetServiceResp* response) { - return m_service_op.GetService(request, response); +CosResult CosAPI::GetService(const GetServiceReq& req, GetServiceResp* resp) { + return m_service_op.GetService(req, resp); } -CosResult CosAPI::HeadBucket(const HeadBucketReq& request, - HeadBucketResp* response) { - return m_bucket_op.HeadBucket(request, response); +CosResult CosAPI::HeadBucket(const HeadBucketReq& req, HeadBucketResp* resp) { + return m_bucket_op.HeadBucket(req, resp); } -CosResult CosAPI::PutBucket(const PutBucketReq& request, - PutBucketResp* response) { - return m_bucket_op.PutBucket(request, response); +CosResult CosAPI::PutBucket(const PutBucketReq& req, PutBucketResp* resp) { + return m_bucket_op.PutBucket(req, resp); } -CosResult CosAPI::GetBucket(const GetBucketReq& request, - GetBucketResp* response) { - return m_bucket_op.GetBucket(request, response); +CosResult CosAPI::GetBucket(const GetBucketReq& req, GetBucketResp* resp) { + return m_bucket_op.GetBucket(req, resp); } -CosResult CosAPI::ListMultipartUpload(const ListMultipartUploadReq& request, - ListMultipartUploadResp* response) { - return m_bucket_op.ListMultipartUpload(request, response); +CosResult CosAPI::ListMultipartUpload(const ListMultipartUploadReq& req, + ListMultipartUploadResp* resp) { + return m_bucket_op.ListMultipartUpload(req, resp); } -CosResult CosAPI::DeleteBucket(const DeleteBucketReq& request, - DeleteBucketResp* response) { - return m_bucket_op.DeleteBucket(request, response); +CosResult CosAPI::DeleteBucket(const DeleteBucketReq& req, + DeleteBucketResp* resp) { + return m_bucket_op.DeleteBucket(req, resp); } -CosResult CosAPI::GetBucketVersioning(const GetBucketVersioningReq& request, - GetBucketVersioningResp* response) { - return m_bucket_op.GetBucketVersioning(request, response); +CosResult CosAPI::GetBucketVersioning(const GetBucketVersioningReq& req, + GetBucketVersioningResp* resp) { + return m_bucket_op.GetBucketVersioning(req, resp); } -CosResult CosAPI::PutBucketVersioning(const PutBucketVersioningReq& request, - PutBucketVersioningResp* response) { - return m_bucket_op.PutBucketVersioning(request, response); +CosResult CosAPI::PutBucketVersioning(const PutBucketVersioningReq& req, + PutBucketVersioningResp* resp) { + return m_bucket_op.PutBucketVersioning(req, resp); } -CosResult CosAPI::GetBucketReplication(const GetBucketReplicationReq& request, - GetBucketReplicationResp* response) { - return m_bucket_op.GetBucketReplication(request, response); +CosResult CosAPI::GetBucketReplication(const GetBucketReplicationReq& req, + GetBucketReplicationResp* resp) { + return m_bucket_op.GetBucketReplication(req, resp); } -CosResult CosAPI::PutBucketReplication(const PutBucketReplicationReq& request, - PutBucketReplicationResp* response) { - return m_bucket_op.PutBucketReplication(request, response); +CosResult CosAPI::PutBucketReplication(const PutBucketReplicationReq& req, + PutBucketReplicationResp* resp) { + return m_bucket_op.PutBucketReplication(req, resp); } -CosResult CosAPI::DeleteBucketReplication( - const DeleteBucketReplicationReq& request, - DeleteBucketReplicationResp* response) { - return m_bucket_op.DeleteBucketReplication(request, response); +CosResult CosAPI::DeleteBucketReplication(const DeleteBucketReplicationReq& req, + DeleteBucketReplicationResp* resp) { + return m_bucket_op.DeleteBucketReplication(req, resp); } -CosResult CosAPI::GetBucketLifecycle(const GetBucketLifecycleReq& request, - GetBucketLifecycleResp* response) { - return m_bucket_op.GetBucketLifecycle(request, response); +CosResult CosAPI::GetBucketLifecycle(const GetBucketLifecycleReq& req, + GetBucketLifecycleResp* resp) { + return m_bucket_op.GetBucketLifecycle(req, resp); } -CosResult CosAPI::PutBucketLifecycle(const PutBucketLifecycleReq& request, - PutBucketLifecycleResp* response) { - return m_bucket_op.PutBucketLifecycle(request, response); +CosResult CosAPI::PutBucketLifecycle(const PutBucketLifecycleReq& req, + PutBucketLifecycleResp* resp) { + return m_bucket_op.PutBucketLifecycle(req, resp); } -CosResult CosAPI::DeleteBucketLifecycle(const DeleteBucketLifecycleReq& request, - DeleteBucketLifecycleResp* response) { - return m_bucket_op.DeleteBucketLifecycle(request, response); +CosResult CosAPI::DeleteBucketLifecycle(const DeleteBucketLifecycleReq& req, + DeleteBucketLifecycleResp* resp) { + return m_bucket_op.DeleteBucketLifecycle(req, resp); } -CosResult CosAPI::GetBucketACL(const GetBucketACLReq& request, - GetBucketACLResp* response) { - return m_bucket_op.GetBucketACL(request, response); +CosResult CosAPI::GetBucketACL(const GetBucketACLReq& req, + GetBucketACLResp* resp) { + return m_bucket_op.GetBucketACL(req, resp); } -CosResult CosAPI::PutBucketACL(const PutBucketACLReq& request, - PutBucketACLResp* response) { - return m_bucket_op.PutBucketACL(request, response); +CosResult CosAPI::PutBucketACL(const PutBucketACLReq& req, + PutBucketACLResp* resp) { + return m_bucket_op.PutBucketACL(req, resp); } -CosResult CosAPI::GetBucketCORS(const GetBucketCORSReq& request, - GetBucketCORSResp* response) { - return m_bucket_op.GetBucketCORS(request, response); +CosResult CosAPI::GetBucketCORS(const GetBucketCORSReq& req, + GetBucketCORSResp* resp) { + return m_bucket_op.GetBucketCORS(req, resp); } -CosResult CosAPI::PutBucketCORS(const PutBucketCORSReq& request, - PutBucketCORSResp* response) { - return m_bucket_op.PutBucketCORS(request, response); +CosResult CosAPI::PutBucketCORS(const PutBucketCORSReq& req, + PutBucketCORSResp* resp) { + return m_bucket_op.PutBucketCORS(req, resp); } -CosResult CosAPI::DeleteBucketCORS(const DeleteBucketCORSReq& request, - DeleteBucketCORSResp* response) { - return m_bucket_op.DeleteBucketCORS(request, response); +CosResult CosAPI::DeleteBucketCORS(const DeleteBucketCORSReq& req, + DeleteBucketCORSResp* resp) { + return m_bucket_op.DeleteBucketCORS(req, resp); } -CosResult CosAPI::PutBucketReferer(const PutBucketRefererReq& request, - PutBucketRefererResp* response) { - return m_bucket_op.PutBucketReferer(request, response); +CosResult CosAPI::PutBucketReferer(const PutBucketRefererReq& req, + PutBucketRefererResp* resp) { + return m_bucket_op.PutBucketReferer(req, resp); } -CosResult CosAPI::GetBucketReferer(const GetBucketRefererReq& request, - GetBucketRefererResp* response) { - return m_bucket_op.GetBucketReferer(request, response); +CosResult CosAPI::GetBucketReferer(const GetBucketRefererReq& req, + GetBucketRefererResp* resp) { + return m_bucket_op.GetBucketReferer(req, resp); } -CosResult CosAPI::PutBucketLogging(const PutBucketLoggingReq& request, - PutBucketLoggingResp* response) { - return m_bucket_op.PutBucketLogging(request, response); +CosResult CosAPI::PutBucketLogging(const PutBucketLoggingReq& req, + PutBucketLoggingResp* resp) { + return m_bucket_op.PutBucketLogging(req, resp); } -CosResult CosAPI::GetBucketLogging(const GetBucketLoggingReq& request, - GetBucketLoggingResp* response) { - return m_bucket_op.GetBucketLogging(request, response); +CosResult CosAPI::GetBucketLogging(const GetBucketLoggingReq& req, + GetBucketLoggingResp* resp) { + return m_bucket_op.GetBucketLogging(req, resp); } -CosResult CosAPI::PutBucketDomain(const PutBucketDomainReq& request, - PutBucketDomainResp* response) { - return m_bucket_op.PutBucketDomain(request, response); +CosResult CosAPI::PutBucketDomain(const PutBucketDomainReq& req, + PutBucketDomainResp* resp) { + return m_bucket_op.PutBucketDomain(req, resp); } -CosResult CosAPI::GetBucketDomain(const GetBucketDomainReq& request, - GetBucketDomainResp* response) { - return m_bucket_op.GetBucketDomain(request, response); +CosResult CosAPI::GetBucketDomain(const GetBucketDomainReq& req, + GetBucketDomainResp* resp) { + return m_bucket_op.GetBucketDomain(req, resp); } -CosResult CosAPI::PutBucketWebsite(const PutBucketWebsiteReq& request, - PutBucketWebsiteResp* response) { - return m_bucket_op.PutBucketWebsite(request, response); +CosResult CosAPI::PutBucketWebsite(const PutBucketWebsiteReq& req, + PutBucketWebsiteResp* resp) { + return m_bucket_op.PutBucketWebsite(req, resp); } -CosResult CosAPI::GetBucketWebsite(const GetBucketWebsiteReq& request, - GetBucketWebsiteResp* response) { - return m_bucket_op.GetBucketWebsite(request, response); +CosResult CosAPI::GetBucketWebsite(const GetBucketWebsiteReq& req, + GetBucketWebsiteResp* resp) { + return m_bucket_op.GetBucketWebsite(req, resp); } -CosResult CosAPI::DeleteBucketWebsite(const DeleteBucketWebsiteReq& request, - DeleteBucketWebsiteResp* response) { - return m_bucket_op.DeleteBucketWebsite(request, response); +CosResult CosAPI::DeleteBucketWebsite(const DeleteBucketWebsiteReq& req, + DeleteBucketWebsiteResp* resp) { + return m_bucket_op.DeleteBucketWebsite(req, resp); } -CosResult CosAPI::PutBucketTagging(const PutBucketTaggingReq& request, - PutBucketTaggingResp* response) { - return m_bucket_op.PutBucketTagging(request, response); +CosResult CosAPI::PutBucketTagging(const PutBucketTaggingReq& req, + PutBucketTaggingResp* resp) { + return m_bucket_op.PutBucketTagging(req, resp); } -CosResult CosAPI::GetBucketTagging(const GetBucketTaggingReq& request, - GetBucketTaggingResp* response) { - return m_bucket_op.GetBucketTagging(request, response); +CosResult CosAPI::GetBucketTagging(const GetBucketTaggingReq& req, + GetBucketTaggingResp* resp) { + return m_bucket_op.GetBucketTagging(req, resp); } -CosResult CosAPI::DeleteBucketTagging(const DeleteBucketTaggingReq& request, - DeleteBucketTaggingResp* response) { - return m_bucket_op.DeleteBucketTagging(request, response); +CosResult CosAPI::DeleteBucketTagging(const DeleteBucketTaggingReq& req, + DeleteBucketTaggingResp* resp) { + return m_bucket_op.DeleteBucketTagging(req, resp); } -CosResult CosAPI::PutBucketInventory(const PutBucketInventoryReq& request, - PutBucketInventoryResp* response) { - return m_bucket_op.PutBucketInventory(request, response); +CosResult CosAPI::PutBucketInventory(const PutBucketInventoryReq& req, + PutBucketInventoryResp* resp) { + return m_bucket_op.PutBucketInventory(req, resp); } -CosResult CosAPI::GetBucketInventory(const GetBucketInventoryReq& request, - GetBucketInventoryResp* response) { - return m_bucket_op.GetBucketInventory(request, response); +CosResult CosAPI::GetBucketInventory(const GetBucketInventoryReq& req, + GetBucketInventoryResp* resp) { + return m_bucket_op.GetBucketInventory(req, resp); } CosResult CosAPI::ListBucketInventoryConfigurations( - const ListBucketInventoryConfigurationsReq& request, - ListBucketInventoryConfigurationsResp* response) { - return m_bucket_op.ListBucketInventoryConfigurations(request, response); + const ListBucketInventoryConfigurationsReq& req, + ListBucketInventoryConfigurationsResp* resp) { + return m_bucket_op.ListBucketInventoryConfigurations(req, resp); } -CosResult CosAPI::DeleteBucketInventory(const DeleteBucketInventoryReq& request, - DeleteBucketInventoryResp* response) { - return m_bucket_op.DeleteBucketInventory(request, response); +CosResult CosAPI::DeleteBucketInventory(const DeleteBucketInventoryReq& req, + DeleteBucketInventoryResp* resp) { + return m_bucket_op.DeleteBucketInventory(req, resp); } -CosResult CosAPI::GetBucketObjectVersions( - const GetBucketObjectVersionsReq& request, - GetBucketObjectVersionsResp* response) { - return m_bucket_op.GetBucketObjectVersions(request, response); +CosResult CosAPI::GetBucketObjectVersions(const GetBucketObjectVersionsReq& req, + GetBucketObjectVersionsResp* resp) { + return m_bucket_op.GetBucketObjectVersions(req, resp); } -CosResult CosAPI::PutObject(const PutObjectByFileReq& request, - PutObjectByFileResp* response) { - return m_object_op.PutObject(request, response); +CosResult CosAPI::PutObject(const PutObjectByFileReq& req, + PutObjectByFileResp* resp) { + return m_object_op.PutObject(req, resp); } -CosResult CosAPI::PutObject(const PutObjectByStreamReq& request, - PutObjectByStreamResp* response) { - return m_object_op.PutObject(request, response); +CosResult CosAPI::PutObject(const PutObjectByStreamReq& req, + PutObjectByStreamResp* resp) { + return m_object_op.PutObject(req, resp); } -CosResult CosAPI::GetObject(const GetObjectByStreamReq& request, - GetObjectByStreamResp* response) { - return m_object_op.GetObject(request, response); +CosResult CosAPI::GetObject(const GetObjectByStreamReq& req, + GetObjectByStreamResp* resp) { + return m_object_op.GetObject(req, resp); } -CosResult CosAPI::GetObject(const GetObjectByFileReq& request, - GetObjectByFileResp* response) { - return m_object_op.GetObject(request, response); +CosResult CosAPI::GetObject(const GetObjectByFileReq& req, + GetObjectByFileResp* resp) { + return m_object_op.GetObject(req, resp); } -CosResult CosAPI::GetObject(const MultiGetObjectReq& request, - MultiGetObjectResp* response) { - return m_object_op.GetObject(request, response); +CosResult CosAPI::GetObject(const MultiGetObjectReq& req, + MultiGetObjectResp* resp) { + return m_object_op.GetObject(req, resp); } std::string CosAPI::GetObjectUrl(const std::string& bucket, @@ -333,98 +325,96 @@ std::string CosAPI::GetObjectUrl(const std::string& bucket, return object_url; } -CosResult CosAPI::DeleteObject(const DeleteObjectReq& request, - DeleteObjectResp* response) { - return m_object_op.DeleteObject(request, response); +CosResult CosAPI::DeleteObject(const DeleteObjectReq& req, + DeleteObjectResp* resp) { + return m_object_op.DeleteObject(req, resp); } -CosResult CosAPI::DeleteObjects(const DeleteObjectsReq& request, - DeleteObjectsResp* response) { - return m_object_op.DeleteObjects(request, response); +CosResult CosAPI::DeleteObjects(const DeleteObjectsReq& req, + DeleteObjectsResp* resp) { + return m_object_op.DeleteObjects(req, resp); } -CosResult CosAPI::HeadObject(const HeadObjectReq& request, - HeadObjectResp* response) { - return m_object_op.HeadObject(request, response); +CosResult CosAPI::HeadObject(const HeadObjectReq& req, HeadObjectResp* resp) { + return m_object_op.HeadObject(req, resp); } -CosResult CosAPI::InitMultiUpload(const InitMultiUploadReq& request, - InitMultiUploadResp* response) { - return m_object_op.InitMultiUpload(request, response); +CosResult CosAPI::InitMultiUpload(const InitMultiUploadReq& req, + InitMultiUploadResp* resp) { + return m_object_op.InitMultiUpload(req, resp); } -CosResult CosAPI::UploadPartData(const UploadPartDataReq& request, - UploadPartDataResp* response) { - return m_object_op.UploadPartData(request, response); +CosResult CosAPI::UploadPartData(const UploadPartDataReq& req, + UploadPartDataResp* resp) { + return m_object_op.UploadPartData(req, resp); } -CosResult CosAPI::UploadPartCopyData(const UploadPartCopyDataReq& request, - UploadPartCopyDataResp* response) { - return m_object_op.UploadPartCopyData(request, response); +CosResult CosAPI::UploadPartCopyData(const UploadPartCopyDataReq& req, + UploadPartCopyDataResp* resp) { + return m_object_op.UploadPartCopyData(req, resp); } -CosResult CosAPI::CompleteMultiUpload(const CompleteMultiUploadReq& request, - CompleteMultiUploadResp* response) { - return m_object_op.CompleteMultiUpload(request, response); +CosResult CosAPI::CompleteMultiUpload(const CompleteMultiUploadReq& req, + CompleteMultiUploadResp* resp) { + return m_object_op.CompleteMultiUpload(req, resp); } -CosResult CosAPI::MultiUploadObject(const MultiUploadObjectReq& request, - MultiUploadObjectResp* response) { - return m_object_op.MultiUploadObject(request, response); +CosResult CosAPI::PutObject(const MultiPutObjectReq& req, + MultiPutObjectResp* resp) { + return m_object_op.MultiUploadObject(req, resp); } -CosResult CosAPI::AbortMultiUpload(const AbortMultiUploadReq& request, - AbortMultiUploadResp* response) { - return m_object_op.AbortMultiUpload(request, response); +CosResult CosAPI::AbortMultiUpload(const AbortMultiUploadReq& req, + AbortMultiUploadResp* resp) { + return m_object_op.AbortMultiUpload(req, resp); } -CosResult CosAPI::ListParts(const ListPartsReq& request, - ListPartsResp* response) { - return m_object_op.ListParts(request, response); +CosResult CosAPI::ListParts(const ListPartsReq& req, ListPartsResp* resp) { + return m_object_op.ListParts(req, resp); } -CosResult CosAPI::GetObjectACL(const GetObjectACLReq& request, - GetObjectACLResp* response) { - return m_object_op.GetObjectACL(request, response); +CosResult CosAPI::GetObjectACL(const GetObjectACLReq& req, + GetObjectACLResp* resp) { + return m_object_op.GetObjectACL(req, resp); } -CosResult CosAPI::PutObjectACL(const PutObjectACLReq& request, - PutObjectACLResp* response) { - return m_object_op.PutObjectACL(request, response); +CosResult CosAPI::PutObjectACL(const PutObjectACLReq& req, + PutObjectACLResp* resp) { + return m_object_op.PutObjectACL(req, resp); } -CosResult CosAPI::PutObjectCopy(const PutObjectCopyReq& request, - PutObjectCopyResp* response) { - return m_object_op.PutObjectCopy(request, response); +CosResult CosAPI::PutObjectCopy(const PutObjectCopyReq& req, + PutObjectCopyResp* resp) { + return m_object_op.PutObjectCopy(req, resp); } -CosResult CosAPI::Copy(const CopyReq& request, CopyResp* response) { - return m_object_op.Copy(request, response); +CosResult CosAPI::Copy(const CopyReq& req, CopyResp* resp) { + return m_object_op.Copy(req, resp); } -CosResult CosAPI::PostObjectRestore(const PostObjectRestoreReq& request, - PostObjectRestoreResp* response) { - return m_object_op.PostObjectRestore(request, response); +CosResult CosAPI::PostObjectRestore(const PostObjectRestoreReq& req, + PostObjectRestoreResp* resp) { + return m_object_op.PostObjectRestore(req, resp); } -CosResult CosAPI::OptionsObject(const OptionsObjectReq& request, - OptionsObjectResp* response) { - return m_object_op.OptionsObject(request, response); +CosResult CosAPI::OptionsObject(const OptionsObjectReq& req, + OptionsObjectResp* resp) { + return m_object_op.OptionsObject(req, resp); } -CosResult CosAPI::SelectObjectContent(const SelectObjectContentReq& request, - SelectObjectContentResp* response) { - return m_object_op.SelectObjectContent(request, response); +CosResult CosAPI::SelectObjectContent(const SelectObjectContentReq& req, + SelectObjectContentResp* resp) { + return m_object_op.SelectObjectContent(req, resp); } -CosResult CosAPI::AppendObject(const AppendObjectReq& request, - AppendObjectResp* response) { - return m_object_op.AppendObject(request, response); +CosResult CosAPI::AppendObject(const AppendObjectReq& req, + AppendObjectResp* resp) { + return m_object_op.AppendObject(req, resp); } -CosResult CosAPI::PutLiveChannel(const PutLiveChannelReq& request, - PutLiveChannelResp* response) { - return m_object_op.PutLiveChannel(request, response); +CosResult CosAPI::PutLiveChannel(const PutLiveChannelReq& req, + PutLiveChannelResp* resp) { + return m_object_op.PutLiveChannel(req, resp); } std::string CosAPI::GetRtmpSignedPublishUrl( @@ -439,110 +429,118 @@ std::string CosAPI::GetRtmpSignedPublishUrl( return rtmp_signed_url + "?" + sign_info; } -CosResult CosAPI::PutLiveChannelSwitch(const PutLiveChannelSwitchReq& request, - PutLiveChannelSwitchResp* response) { - return m_object_op.PutLiveChannelSwitch(request, response); +CosResult CosAPI::PutLiveChannelSwitch(const PutLiveChannelSwitchReq& req, + PutLiveChannelSwitchResp* resp) { + return m_object_op.PutLiveChannelSwitch(req, resp); } -CosResult CosAPI::GetLiveChannel(const GetLiveChannelReq& request, - GetLiveChannelResp* response) { - return m_object_op.GetLiveChannel(request, response); +CosResult CosAPI::GetLiveChannel(const GetLiveChannelReq& req, + GetLiveChannelResp* resp) { + return m_object_op.GetLiveChannel(req, resp); } -CosResult CosAPI::GetLiveChannelHistory(const GetLiveChannelHistoryReq& request, - GetLiveChannelHistoryResp* response) { - return m_object_op.GetLiveChannelHistory(request, response); +CosResult CosAPI::GetLiveChannelHistory(const GetLiveChannelHistoryReq& req, + GetLiveChannelHistoryResp* resp) { + return m_object_op.GetLiveChannelHistory(req, resp); } -CosResult CosAPI::GetLiveChannelStatus(const GetLiveChannelStatusReq& request, - GetLiveChannelStatusResp* response) { - return m_object_op.GetLiveChannelStatus(request, response); +CosResult CosAPI::GetLiveChannelStatus(const GetLiveChannelStatusReq& req, + GetLiveChannelStatusResp* resp) { + return m_object_op.GetLiveChannelStatus(req, resp); } -CosResult CosAPI::DeleteLiveChannel(const DeleteLiveChannelReq& request, - DeleteLiveChannelResp* response) { - return m_object_op.DeleteLiveChannel(request, response); +CosResult CosAPI::DeleteLiveChannel(const DeleteLiveChannelReq& req, + DeleteLiveChannelResp* resp) { + return m_object_op.DeleteLiveChannel(req, resp); } -CosResult CosAPI::GetLiveChannelVodPlaylist( - const GetLiveChannelVodPlaylistReq& request, - GetLiveChannelVodPlaylistResp* response) { - return m_object_op.GetLiveChannelVodPlaylist(request, response); +CosResult +CosAPI::GetLiveChannelVodPlaylist(const GetLiveChannelVodPlaylistReq& req, + GetLiveChannelVodPlaylistResp* resp) { + return m_object_op.GetLiveChannelVodPlaylist(req, resp); } -CosResult CosAPI::PostLiveChannelVodPlaylist( - const PostLiveChannelVodPlaylistReq& request, - PostLiveChannelVodPlaylistResp* response) { - return m_object_op.PostLiveChannelVodPlaylist(request, response); +CosResult +CosAPI::PostLiveChannelVodPlaylist(const PostLiveChannelVodPlaylistReq& req, + PostLiveChannelVodPlaylistResp* resp) { + return m_object_op.PostLiveChannelVodPlaylist(req, resp); } -CosResult CosAPI::ListLiveChannel(const ListLiveChannelReq& request, - ListLiveChannelResp* response) { - return m_bucket_op.ListLiveChannel(request, response); +CosResult CosAPI::ListLiveChannel(const ListLiveChannelReq& req, + ListLiveChannelResp* resp) { + return m_bucket_op.ListLiveChannel(req, resp); } -CosResult CosAPI::PutBucketIntelligentTiering( - const PutBucketIntelligentTieringReq& request, - PutBucketIntelligentTieringResp* response) { - return m_bucket_op.PutBucketIntelligentTiering(request, response); +CosResult +CosAPI::PutBucketIntelligentTiering(const PutBucketIntelligentTieringReq& req, + PutBucketIntelligentTieringResp* resp) { + return m_bucket_op.PutBucketIntelligentTiering(req, resp); } -CosResult CosAPI::GetBucketIntelligentTiering( - const GetBucketIntelligentTieringReq& request, - GetBucketIntelligentTieringResp* response) { - return m_bucket_op.GetBucketIntelligentTiering(request, response); +CosResult +CosAPI::GetBucketIntelligentTiering(const GetBucketIntelligentTieringReq& req, + GetBucketIntelligentTieringResp* resp) { + return m_bucket_op.GetBucketIntelligentTiering(req, resp); } -CosResult CosAPI::ResumableGetObject(const MultiGetObjectReq& request, - MultiGetObjectResp* response) { - return m_object_op.ResumableGetObject(request, response); +CosResult CosAPI::ResumableGetObject(const MultiGetObjectReq& req, + MultiGetObjectResp* resp) { + return m_object_op.ResumableGetObject(req, resp); } -SharedTransferHandler CosAPI::PutObjectAsync( - const MultiUploadObjectReq& request, MultiUploadObjectResp* response) { - SharedTransferHandler handler( - new TransferHandler(request.GetBucketName(), request.GetObjectName(), 0)); - uint64_t file_size = FileUtil::GetFileLen(request.GetLocalFilePath()); +// SharedAsyncContext CosAPI::PutObjectAsync(const PutObjectByFileReq& req) { +// TODO +//} + +SharedAsyncContext CosAPI::PutObjectAsync(const MultiPutObjectReq& req) { + SharedTransferHandler handler(new TransferHandler( + req.GetBucketName(), req.GetObjectName(), req.GetLocalFilePath())); + uint64_t file_size = FileUtil::GetFileLen(req.GetLocalFilePath()); handler->SetTotalSize(file_size); - handler->SetTransferProgressCallback(request.GetTransferProgressCallback()); - handler->SetTransferStatusCallback(request.GetTransferStatusCallback()); - handler->SetTransferCallbackUserData(request.GetTransferCallbackUserData()); - TaskFunc fn = [=]() { - m_object_op.MultiUploadObject(request, response, handler); - }; + handler->SetTransferProgressCallback(req.GetTransferProgressCallback()); + handler->SetDoneCallback(req.GetDoneCallback()); + handler->SetUserData(req.GetUserData()); + TaskFunc fn = [=]() { m_object_op.MultiUploadObject(req, nullptr, handler); }; GetGlobalTaskManager().start(new AsyncTask(std::move(fn))); - return handler; + + SharedAsyncContext context(new AsyncContext(handler)); + return context; } -SharedTransferHandler CosAPI::GetObjectAsync(const MultiGetObjectReq& request, - MultiGetObjectResp* response) { - SharedTransferHandler handler( - new TransferHandler(request.GetBucketName(), request.GetObjectName(), 0)); - handler->SetTransferProgressCallback(request.GetTransferProgressCallback()); - handler->SetTransferStatusCallback(request.GetTransferStatusCallback()); - handler->SetTransferCallbackUserData(request.GetTransferCallbackUserData()); +// SharedAsyncContext CosAPI::GetObjectAsync(const GetObjectByFileReq& req) { +// TODO +//} + +SharedAsyncContext CosAPI::GetObjectAsync(const MultiGetObjectReq& req) { + SharedTransferHandler handler(new TransferHandler( + req.GetBucketName(), req.GetObjectName(), req.GetLocalFilePath())); + handler->SetTransferProgressCallback(req.GetTransferProgressCallback()); + handler->SetDoneCallback(req.GetDoneCallback()); + handler->SetUserData(reinterpret_cast(req.GetUserData())); TaskFunc fn = [=]() { - m_object_op.MultiThreadDownload(request, response, handler); + m_object_op.MultiThreadDownload(req, nullptr, handler); }; GetGlobalTaskManager().start(new AsyncTask(std::move(fn))); - return handler; + + SharedAsyncContext context(new AsyncContext(handler)); + return context; } -CosResult CosAPI::PutObjects(const PutObjectsByDirectoryReq& request, - PutObjectsByDirectoryResp* response) { - return m_object_op.PutObjects(request, response); +CosResult CosAPI::PutObjects(const PutObjectsByDirectoryReq& req, + PutObjectsByDirectoryResp* resp) { + return m_object_op.PutObjects(req, resp); } -CosResult CosAPI::PutDirectory(const PutDirectoryReq& request, - PutDirectoryResp* response) { - return m_object_op.PutDirectory(request, response); +CosResult CosAPI::PutDirectory(const PutDirectoryReq& req, + PutDirectoryResp* resp) { + return m_object_op.PutDirectory(req, resp); } -CosResult CosAPI::DeleteObjects(const DeleteObjectsByPrefixReq& request, - DeleteObjectsByPrefixResp* response) { +CosResult CosAPI::DeleteObjects(const DeleteObjectsByPrefixReq& req, + DeleteObjectsByPrefixResp* resp) { CosResult get_bucket_result; - GetBucketReq get_bucket_req(request.GetBucketName()); - get_bucket_req.SetPrefix(request.GetPrefix()); + GetBucketReq get_bucket_req(req.GetBucketName()); + get_bucket_req.SetPrefix(req.GetPrefix()); bool is_truncated = false; do { @@ -551,11 +549,11 @@ CosResult CosAPI::DeleteObjects(const DeleteObjectsByPrefixReq& request, if (get_bucket_result.IsSucc()) { std::vector contents = get_bucket_resp.GetContents(); for (auto& content : contents) { - DeleteObjectReq del_req(request.GetBucketName(), content.m_key); + DeleteObjectReq del_req(req.GetBucketName(), content.m_key); DeleteObjectResp del_resp; CosResult del_result = DeleteObject(del_req, &del_resp); if (del_result.IsSucc()) { - response->m_succ_del_objs.push_back(content.m_key); + resp->m_succ_del_objs.push_back(content.m_key); } else { return del_result; } @@ -569,78 +567,74 @@ CosResult CosAPI::DeleteObjects(const DeleteObjectsByPrefixReq& request, return get_bucket_result; }; -CosResult CosAPI::MoveObject(const MoveObjectReq& request, - MoveObjectResp* response) { - return m_object_op.MoveObject(request, response); +CosResult CosAPI::MoveObject(const MoveObjectReq& req, MoveObjectResp* resp) { + return m_object_op.MoveObject(req, resp); } -CosResult CosAPI::PutImage(const PutImageByFileReq& request, - PutImageByFileResp* response) { - return m_object_op.PutImage(request, response); +CosResult CosAPI::PutImage(const PutImageByFileReq& req, + PutImageByFileResp* resp) { + return m_object_op.PutImage(req, resp); } -CosResult CosAPI::CloudImageProcess(const CloudImageProcessReq& request, - CloudImageProcessResp* response) { - return m_object_op.CloudImageProcess(request, response); +CosResult CosAPI::CloudImageProcess(const CloudImageProcessReq& req, + CloudImageProcessResp* resp) { + return m_object_op.CloudImageProcess(req, resp); } -CosResult CosAPI::GetQRcode(const GetQRcodeReq& request, - GetQRcodeResp* response) { - return m_object_op.GetQRcode(request, response); +CosResult CosAPI::GetQRcode(const GetQRcodeReq& req, GetQRcodeResp* resp) { + return m_object_op.GetQRcode(req, resp); } -CosResult CosAPI::DescribeDocProcessBuckets( - const DescribeDocProcessBucketsReq& request, - DescribeDocProcessBucketsResp* response) { - return m_object_op.DescribeDocProcessBuckets(request, response); +CosResult +CosAPI::DescribeDocProcessBuckets(const DescribeDocProcessBucketsReq& req, + DescribeDocProcessBucketsResp* resp) { + return m_object_op.DescribeDocProcessBuckets(req, resp); } -CosResult CosAPI::DocPreview(const DocPreviewReq& request, - DocPreviewResp* response) { - return m_object_op.DocPreview(request, response); +CosResult CosAPI::DocPreview(const DocPreviewReq& req, DocPreviewResp* resp) { + return m_object_op.DocPreview(req, resp); } -CosResult CosAPI::CreateDocProcessJobs(const CreateDocProcessJobsReq& request, - CreateDocProcessJobsResp* response) { - return m_bucket_op.CreateDocProcessJobs(request, response); +CosResult CosAPI::CreateDocProcessJobs(const CreateDocProcessJobsReq& req, + CreateDocProcessJobsResp* resp) { + return m_bucket_op.CreateDocProcessJobs(req, resp); } -CosResult CosAPI::DescribeDocProcessJob(const DescribeDocProcessJobReq& request, - DescribeDocProcessJobResp* response) { - return m_bucket_op.DescribeDocProcessJob(request, response); +CosResult CosAPI::DescribeDocProcessJob(const DescribeDocProcessJobReq& req, + DescribeDocProcessJobResp* resp) { + return m_bucket_op.DescribeDocProcessJob(req, resp); } -CosResult CosAPI::DescribeDocProcessJobs( - const DescribeDocProcessJobsReq& request, - DescribeDocProcessJobsResp* response) { - return m_bucket_op.DescribeDocProcessJobs(request, response); +CosResult CosAPI::DescribeDocProcessJobs(const DescribeDocProcessJobsReq& req, + DescribeDocProcessJobsResp* resp) { + return m_bucket_op.DescribeDocProcessJobs(req, resp); } -CosResult CosAPI::DescribeDocProcessQueues( - const DescribeDocProcessQueuesReq& request, - DescribeDocProcessQueuesResp* response) { - return m_bucket_op.DescribeDocProcessQueues(request, response); +CosResult +CosAPI::DescribeDocProcessQueues(const DescribeDocProcessQueuesReq& req, + DescribeDocProcessQueuesResp* resp) { + return m_bucket_op.DescribeDocProcessQueues(req, resp); } -CosResult CosAPI::UpdateDocProcessQueue(const UpdateDocProcessQueueReq& request, - UpdateDocProcessQueueResp* response) { - return m_bucket_op.UpdateDocProcessQueue(request, response); +CosResult CosAPI::UpdateDocProcessQueue(const UpdateDocProcessQueueReq& req, + UpdateDocProcessQueueResp* resp) { + return m_bucket_op.UpdateDocProcessQueue(req, resp); } -CosResult CosAPI::DescribeMediaBuckets(const DescribeMediaBucketsReq& request, - DescribeMediaBucketsResp* response) { - return m_bucket_op.DescribeMediaBuckets(request, response); +CosResult CosAPI::DescribeMediaBuckets(const DescribeMediaBucketsReq& req, + DescribeMediaBucketsResp* resp) { + return m_bucket_op.DescribeMediaBuckets(req, resp); } -CosResult CosAPI::GetSnapshot(const GetSnapshotReq& request, - GetSnapshotResp* response) { - return m_object_op.GetObject(static_cast(request), - static_cast(response)); +CosResult CosAPI::GetSnapshot(const GetSnapshotReq& req, + GetSnapshotResp* resp) { + return m_object_op.GetObject(static_cast(req), + static_cast(resp)); } -CosResult CosAPI::GetMediaInfo(const GetMediaInfoReq& request, - GetMediaInfoResp* response) { - return m_object_op.GetMediaInfo(request, response); +CosResult CosAPI::GetMediaInfo(const GetMediaInfoReq& req, + GetMediaInfoResp* resp) { + return m_object_op.GetMediaInfo(req, resp); } } // namespace qcloud_cos diff --git a/src/op/base_op.cpp b/src/op/base_op.cpp index c1dcbb3..551dfc1 100644 --- a/src/op/base_op.cpp +++ b/src/op/base_op.cpp @@ -53,11 +53,11 @@ CosResult BaseOp::NormalAction( const std::string& req_body, bool check_body, BaseResp* resp) { CosResult result; if (!CheckConfigValidation()) { - std::string err_info = + std::string err_msg = "Invalid access_key secret_key or region, please check your " "configuration"; - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + SDK_LOG_ERR("%s", err_msg.c_str()); + result.SetErrorMsg(err_msg); result.SetFail(); return result; } @@ -83,7 +83,7 @@ CosResult BaseOp::NormalAction( AuthTool::Sign(GetAccessKey(), GetSecretKey(), req.GetMethod(), req.GetPath(), req_headers, req_params); if (auth_str.empty()) { - result.SetErrorInfo( + result.SetErrorMsg( "Generate auth str fail, check your access_key/secret_key."); return result; } @@ -100,7 +100,7 @@ CosResult BaseOp::NormalAction( req.GetConnTimeoutInms(), req.GetRecvTimeoutInms(), &resp_headers, &resp_body, &err_msg); if (http_code == -1) { - result.SetErrorInfo(err_msg); + result.SetErrorMsg(err_msg); return result; } @@ -109,12 +109,12 @@ CosResult BaseOp::NormalAction( if (http_code > 299 || http_code < 200) { // 无法解析的错误, 填充到cos_result的error_info中 if (!result.ParseFromHttpResponse(resp_headers, resp_body)) { - result.SetErrorInfo(resp_body); + result.SetErrorMsg(resp_body); } } else { // 某些请求,如PutObjectCopy/Complete请求需要进一步检查Body if (check_body && result.ParseFromHttpResponse(resp_headers, resp_body)) { - result.SetErrorInfo(resp_body); + result.SetErrorMsg(resp_body); return result; } @@ -134,11 +134,11 @@ CosResult BaseOp::DownloadAction(const std::string& host, BaseResp* resp, std::ostream& os) { CosResult result; if (!CheckConfigValidation()) { - std::string err_info = + std::string err_msg = "Invalid access_key secret_key or region, please check your " "configuration"; - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + SDK_LOG_ERR("%s", err_msg.c_str()); + result.SetErrorMsg(err_msg); result.SetFail(); return result; } @@ -162,7 +162,7 @@ CosResult BaseOp::DownloadAction(const std::string& host, AuthTool::Sign(GetAccessKey(), GetSecretKey(), req.GetMethod(), req.GetPath(), req_headers, req_params); if (auth_str.empty()) { - result.SetErrorInfo( + result.SetErrorMsg( "Generate auth str fail, check your access_key/secret_key."); return result; } @@ -180,7 +180,7 @@ CosResult BaseOp::DownloadAction(const std::string& host, req.GetConnTimeoutInms(), req.GetRecvTimeoutInms(), &resp_headers, &xml_err_str, os, &err_msg, &real_byte, req.CheckMD5()); if (http_code == -1) { - result.SetErrorInfo(err_msg); + result.SetErrorMsg(err_msg); return result; } @@ -190,7 +190,7 @@ CosResult BaseOp::DownloadAction(const std::string& host, if (http_code > 299 || http_code < 200) { // 无法解析的错误, 填充到cos_result的error_info中 if (!result.ParseFromHttpResponse(resp_headers, xml_err_str)) { - result.SetErrorInfo(xml_err_str); + result.SetErrorMsg(xml_err_str); } } else { result.SetSucc(); @@ -203,7 +203,7 @@ CosResult BaseOp::DownloadAction(const std::string& host, // case. if (result.IsSucc() && resp->GetContentLength() != real_byte) { result.SetFail(); - result.SetErrorInfo("Download failed with incomplete file"); + result.SetErrorMsg("Download failed with incomplete file"); SDK_LOG_ERR("Response content length %" PRIu64 "is not same to real recv byte %" PRIu64, resp->GetContentLength(), real_byte); @@ -220,11 +220,11 @@ CosResult BaseOp::UploadAction( std::istream& is, BaseResp* resp) { CosResult result; if (!CheckConfigValidation()) { - std::string err_info = + std::string err_msg = "Invalid access_key secret_key or region, please check your " "configuration"; - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + SDK_LOG_ERR("%s", err_msg.c_str()); + result.SetErrorMsg(err_msg); result.SetFail(); return result; } @@ -250,7 +250,7 @@ CosResult BaseOp::UploadAction( AuthTool::Sign(GetAccessKey(), GetSecretKey(), req.GetMethod(), req.GetPath(), req_headers, req_params); if (auth_str.empty()) { - result.SetErrorInfo( + result.SetErrorMsg( "Generate auth str fail, check your access_key/secret_key."); return result; } @@ -267,7 +267,7 @@ CosResult BaseOp::UploadAction( req.GetConnTimeoutInms(), req.GetRecvTimeoutInms(), &resp_headers, &resp_body, &err_msg); if (http_code == -1) { - result.SetErrorInfo(err_msg); + result.SetErrorMsg(err_msg); return result; } @@ -276,7 +276,7 @@ CosResult BaseOp::UploadAction( if (http_code > 299 || http_code < 200) { // 无法解析的错误, 填充到cos_result的error_info中 if (!result.ParseFromHttpResponse(resp_headers, resp_body)) { - result.SetErrorInfo(resp_body); + result.SetErrorMsg(resp_body); } } else { result.SetSucc(); diff --git a/src/op/bucket_op.cpp b/src/op/bucket_op.cpp index f847a80..2075c29 100644 --- a/src/op/bucket_op.cpp +++ b/src/op/bucket_op.cpp @@ -88,7 +88,7 @@ CosResult BucketOp::PutBucketVersioning(const PutBucketVersioningReq& req, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate PutBucketVersioning Request Body fail."); + result.SetErrorMsg("Generate PutBucketVersioning Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -118,7 +118,7 @@ CosResult BucketOp::PutBucketReplication(const PutBucketReplicationReq& req, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate PutBucketReplication Request Body fail."); + result.SetErrorMsg("Generate PutBucketReplication Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -156,7 +156,7 @@ CosResult BucketOp::PutBucketLifecycle(const PutBucketLifecycleReq& req, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate PutBucketLifecycle Request Body fail."); + result.SetErrorMsg("Generate PutBucketLifecycle Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -203,7 +203,7 @@ CosResult BucketOp::PutBucketACL(const PutBucketACLReq& req, headers.find("x-cos-grant-write") == headers.end() && headers.find("x-cos-grant-full-control") == headers.end()) { if (!req.GenerateRequestBody(&req_body)) { - result.SetErrorInfo("Generate PutBucketACL Request Body fail."); + result.SetErrorMsg("Generate PutBucketACL Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -231,7 +231,7 @@ CosResult BucketOp::PutBucketCORS(const PutBucketCORSReq& req, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate PutBucketCORS Request Body fail."); + result.SetErrorMsg("Generate PutBucketCORS Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -277,7 +277,7 @@ CosResult BucketOp::PutBucketLogging(const PutBucketLoggingReq& req, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate PutBucketLogging Request Body fail."); + result.SetErrorMsg("Generate PutBucketLogging Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -307,7 +307,7 @@ CosResult BucketOp::PutBucketDomain(const PutBucketDomainReq& req, if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate PutBucketDomain Request Body fail."); + result.SetErrorMsg("Generate PutBucketDomain Request Body fail."); return result; } @@ -338,7 +338,7 @@ CosResult BucketOp::PutBucketWebsite(const PutBucketWebsiteReq& req, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate PutBucketWebsite Request Body fail."); + result.SetErrorMsg("Generate PutBucketWebsite Request Body fail."); return result; } @@ -370,7 +370,7 @@ CosResult BucketOp::PutBucketTagging(const PutBucketTaggingReq& req, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate PutBucketWebsite Request Body fail."); + result.SetErrorMsg("Generate PutBucketWebsite Request Body fail."); return result; } @@ -410,13 +410,13 @@ CosResult BucketOp::PutBucketInventory(const PutBucketInventoryReq& req, // id必须设置. if (!req.HasId()) { CosResult result; - result.SetErrorInfo("PutBucketinventory need to set Id."); + result.SetErrorMsg("PutBucketinventory need to set Id."); return result; } std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate PutBucketWebsite Request Body fail."); + result.SetErrorMsg("Generate PutBucketWebsite Request Body fail."); return result; } @@ -439,7 +439,7 @@ CosResult BucketOp::GetBucketInventory(const GetBucketInventoryReq& req, // id必须设置. if (!req.HasId()) { CosResult result; - result.SetErrorInfo("GetBucketinventory need to set Id."); + result.SetErrorMsg("GetBucketinventory need to set Id."); return result; } @@ -465,7 +465,7 @@ CosResult BucketOp::DeleteBucketInventory(const DeleteBucketInventoryReq& req, // id必须设置. if (!req.HasId()) { CosResult result; - result.SetErrorInfo("DeleteBucketinventory need to set Id."); + result.SetErrorMsg("DeleteBucketinventory need to set Id."); return result; } @@ -500,7 +500,7 @@ CosResult BucketOp::PutBucketIntelligentTiering( std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate PutBucketWebsite Request Body fail."); + result.SetErrorMsg("Generate PutBucketWebsite Request Body fail."); return result; } @@ -533,7 +533,7 @@ CosResult BucketOp::ProcessReq(const BucketReq& req, BaseResp* resp, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo("Generate request body fail."); + result.SetErrorMsg("Generate request body fail."); return result; } if (!req_body.empty()) { diff --git a/src/op/cos_result.cpp b/src/op/cos_result.cpp index 920df05..e25d351 100644 --- a/src/op/cos_result.cpp +++ b/src/op/cos_result.cpp @@ -44,7 +44,7 @@ bool CosResult::ParseFromHttpResponse( rapidxml::xml_node<>* root = doc.first_node(kErrorRoot.c_str()); if (NULL == root) { // SDK_LOG_INFO("Miss root node=Error, xml_body=%s", body.c_str()); - SetErrorMsg(body); + // SetErrorMsg(body); return false; } @@ -75,7 +75,6 @@ std::string CosResult::DebugString() const { std::string ret = ""; ret = "IsSucc=" + std::string(m_is_succ ? "true" : "false") + "\n" + "HttpStatus=" + StringUtil::IntToString(m_http_status) + "\n" + - "InternalErrorInfo=" + m_error_info + "\n" + "RemoteReturn=[\n" + "\tErrorCode=" + m_err_code + "\tErrorMsg=" + m_err_msg + "\tResourceAddr=" + m_resource_addr + "\tXCosRequestId=" + m_x_cos_request_id + diff --git a/src/op/file_download_task.cpp b/src/op/file_download_task.cpp index 8606e35..63fdfb6 100644 --- a/src/op/file_download_task.cpp +++ b/src/op/file_download_task.cpp @@ -1,11 +1,11 @@ #include "op/file_download_task.h" -#include #include #include +#include -#include "util/http_sender.h" #include "cos_sys_config.h" +#include "util/http_sender.h" namespace qcloud_cos { @@ -15,79 +15,79 @@ FileDownTask::FileDownTask(const std::string& full_url, uint64_t conn_timeout_in_ms, uint64_t recv_timeout_in_ms, const SharedTransferHandler& handler, - uint64_t offset, - unsigned char* pbuf, + uint64_t offset, unsigned char* pbuf, const size_t data_len) - : m_full_url(full_url), m_headers(headers), m_params(params), + : m_full_url(full_url), + m_headers(headers), + m_params(params), m_conn_timeout_in_ms(conn_timeout_in_ms), m_recv_timeout_in_ms(recv_timeout_in_ms), m_handler(handler), - m_offset(offset), m_data_buf_ptr(pbuf), - m_data_len(data_len), m_resp(""), - m_is_task_success(false), m_real_down_len(0) { -} + m_offset(offset), + m_data_buf_ptr(pbuf), + m_data_len(data_len), + m_resp(""), + m_is_task_success(false), + m_real_down_len(0) {} void FileDownTask::run() { - m_resp = ""; - m_is_task_success = false; - DownTask(); + m_resp = ""; + m_is_task_success = false; + DownTask(); } -void FileDownTask::SetDownParams(unsigned char* pbuf, size_t data_len, uint64_t offset) { - m_data_buf_ptr = pbuf; - m_data_len = data_len; - m_offset = offset; +void FileDownTask::SetDownParams(unsigned char* pbuf, size_t data_len, + uint64_t offset) { + m_data_buf_ptr = pbuf; + m_data_len = data_len; + m_offset = offset; } -size_t FileDownTask::GetDownLoadLen() { - return m_real_down_len; -} +size_t FileDownTask::GetDownLoadLen() { return m_real_down_len; } -bool FileDownTask::IsTaskSuccess() { - return m_is_task_success; -} +bool FileDownTask::IsTaskSuccess() { return m_is_task_success; } -std::string FileDownTask::GetTaskResp() { - return m_resp; -} +std::string FileDownTask::GetTaskResp() { return m_resp; } -int FileDownTask::GetHttpStatus() { - return m_http_status; -} +int FileDownTask::GetHttpStatus() { return m_http_status; } std::map FileDownTask::GetRespHeaders() { - return m_resp_headers; + return m_resp_headers; } void FileDownTask::DownTask() { - char range_head[128]; - memset(range_head, 0, sizeof(range_head)); - snprintf(range_head, sizeof(range_head), "bytes=%llu-%llu", - m_offset, (m_offset + m_data_len - 1)); + char range_head[128]; + memset(range_head, 0, sizeof(range_head)); + snprintf(range_head, sizeof(range_head), "bytes=%llu-%llu", m_offset, + (m_offset + m_data_len - 1)); - // 增加Range头域,避免大文件时将整个文件下载 - m_headers["Range"] = range_head; + // 增加Range头域,避免大文件时将整个文件下载 + m_headers["Range"] = range_head; + int try_times = 0; + do { + try_times++; if (m_handler) { - SDK_LOG_INFO("transfer send GET request"); - std::istringstream iss(""); - std::ostringstream oss; - m_http_status = HttpSender::TransferSendRequest(m_handler, "GET", m_full_url, m_params, m_headers, - iss, m_conn_timeout_in_ms, m_recv_timeout_in_ms, - &m_resp_headers, oss, &m_err_msg, false); - m_resp = oss.str(); + SDK_LOG_INFO("transfer send GET request"); + std::istringstream iss(""); + std::ostringstream oss; + m_http_status = HttpSender::TransferSendRequest( + m_handler, "GET", m_full_url, m_params, m_headers, iss, + m_conn_timeout_in_ms, m_recv_timeout_in_ms, &m_resp_headers, oss, + &m_err_msg, false); + m_resp = oss.str(); } else { - m_http_status = HttpSender::SendRequest("GET", m_full_url, m_params, m_headers, - "", m_conn_timeout_in_ms, m_recv_timeout_in_ms, - &m_resp_headers, &m_resp, &m_err_msg); + m_http_status = HttpSender::SendRequest( + "GET", m_full_url, m_params, m_headers, "", m_conn_timeout_in_ms, + m_recv_timeout_in_ms, &m_resp_headers, &m_resp, &m_err_msg); } //当实际长度小于请求的数据长度时httpcode为206 if (m_http_status != 200 && m_http_status != 206) { - SDK_LOG_ERR("FileDownload: url(%s) fail, httpcode:%d, resp: %s", - m_full_url.c_str(), m_http_status, m_resp.c_str()); - m_is_task_success = false; - m_real_down_len = 0; - return; + SDK_LOG_ERR("FileDownload: url(%s) fail, httpcode:%d, resp: %s, try_times:%d", + m_full_url.c_str(), m_http_status, m_resp.c_str(), try_times); + m_is_task_success = false; + m_real_down_len = 0; + continue; } size_t buf_max_size = m_data_len; @@ -97,6 +97,9 @@ void FileDownTask::DownTask() { m_is_task_success = true; m_resp = ""; return; + } while (!m_is_task_success && try_times <= kMaxRetryTimes); + + return; } -} // namespace qcloud_cos +} // namespace qcloud_cos diff --git a/src/op/object_op.cpp b/src/op/object_op.cpp index c1bc847..f8d1536 100644 --- a/src/op/object_op.cpp +++ b/src/op/object_op.cpp @@ -77,7 +77,7 @@ std::string ObjectOp::GetResumableUploadID(const std::string& bucket_name, return ""; } -bool ObjectOp::CheckSinglePart(const MultiUploadObjectReq& req, uint64_t offset, +bool ObjectOp::CheckSinglePart(const MultiPutObjectReq& req, uint64_t offset, uint64_t local_part_size, uint64_t size, const std::string& etag) { if (local_part_size != size) { @@ -132,7 +132,7 @@ bool ObjectOp::CheckSinglePart(const MultiUploadObjectReq& req, uint64_t offset, return true; } -bool ObjectOp::CheckUploadPart(const MultiUploadObjectReq& req, +bool ObjectOp::CheckUploadPart(const MultiPutObjectReq& req, const std::string& bucket_name, const std::string& object_name, const std::string& uploadid, @@ -309,6 +309,13 @@ bool ObjectOp::CheckResumableDownloadTask( } } +void ObjectOp::SetResultAndLogError(CosResult& result, + const std::string& err_msg) { + SDK_LOG_ERR("%s", err_msg.c_str()); + result.SetErrorMsg(err_msg); + result.SetFail(); +} + CosResult ObjectOp::HeadObject(const HeadObjectReq& req, HeadObjectResp* resp) { std::string host = CosSysConfig::GetHost(GetAppId(), m_config->GetRegion(), req.GetBucketName()); @@ -334,8 +341,8 @@ CosResult ObjectOp::GetObject(const GetObjectByFileReq& req, std::ofstream ofs(req.GetLocalFilePath().c_str(), std::ios::out | std::ios::binary | std::ios::trunc); if (!ofs.is_open()) { - result.SetErrorInfo("Open local file fail, local file=" + - req.GetLocalFilePath()); + result.SetErrorMsg("Open local file fail, local file=" + + req.GetLocalFilePath()); return result; } result = DownloadAction(host, path, req, resp, ofs); @@ -389,7 +396,7 @@ CosResult ObjectOp::PutObject(const PutObjectByStreamReq& req, if (result.IsSucc() && need_check_etag && !StringUtil::IsV4ETag(resp->GetEtag()) && md5_str != resp->GetEtag()) { result.SetFail(); - result.SetErrorInfo("Response etag is not correct, Please try again."); + result.SetErrorMsg("Response etag is not correct, Please try again."); SDK_LOG_ERR( "Response etag is not correct, Please try again. Expect md5 is %s, " "but return etag is %s. RequestId=%s", @@ -412,9 +419,9 @@ CosResult ObjectOp::PutObject(const PutObjectByFileReq& req, std::ifstream ifs(req.GetLocalFilePath().c_str(), std::ios::in | std::ios::binary); if (!ifs.is_open()) { - std::string err_info = "Failed to open file " + req.GetLocalFilePath(); - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + std::string err_msg = "Failed to open file " + req.GetLocalFilePath(); + SDK_LOG_ERR("%s", err_msg.c_str()); + result.SetErrorMsg(err_msg); return result; } @@ -441,7 +448,7 @@ CosResult ObjectOp::PutObject(const PutObjectByFileReq& req, if (result.IsSucc() && need_check_etag && !StringUtil::IsV4ETag(resp->GetEtag()) && md5_str != resp->GetEtag()) { result.SetFail(); - result.SetErrorInfo("Response etag is not correct, Please try again."); + result.SetErrorMsg("Response etag is not correct, Please try again."); SDK_LOG_ERR( "Response etag is not correct, Please try again. Expect md5 is %s," "but return etag is %s. RequestId=%s", @@ -458,7 +465,7 @@ CosResult ObjectOp::DeleteObject(const DeleteObjectReq& req, CosResult result; std::string object_name = req.GetObjectName(); if (object_name.empty()) { - result.SetErrorInfo("Delete object's name is empty."); + result.SetErrorMsg("Delete object's name is empty."); return result; } @@ -479,7 +486,7 @@ CosResult ObjectOp::DeleteObjects(const DeleteObjectsReq& req, std::map additional_headers; std::map additional_params; if (!req.GenerateRequestBody(&req_body)) { - result.SetErrorInfo("Generate DeleteObjects Request Body fail."); + result.SetErrorMsg("Generate DeleteObjects Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -489,10 +496,14 @@ CosResult ObjectOp::DeleteObjects(const DeleteObjectsReq& req, req_body, false, resp); } -CosResult ObjectOp::MultiUploadObject(const MultiUploadObjectReq& req, - MultiUploadObjectResp* resp, +CosResult ObjectOp::MultiUploadObject(const MultiPutObjectReq& req, + MultiPutObjectResp* resp, const SharedTransferHandler& handler) { - uint64_t app_id = GetAppId(); + if (!handler && !resp) { + CosResult result; + SetResultAndLogError(result, "invalid input parameter"); + return result; + } std::string bucket_name = req.GetBucketName(); std::string object_name = req.GetObjectName(); @@ -539,26 +550,19 @@ CosResult ObjectOp::MultiUploadObject(const MultiUploadObjectReq& req, init_req.SetRecvTimeoutInms(req.GetRecvTimeoutInms()); init_result = InitMultiUpload(init_req, &init_resp); if (!init_result.IsSucc()) { - std::string err_info = - "MultiUploadObject failed, init multipart upload failed"; - SDK_LOG_ERR("%s", err_info.c_str()); - init_result.SetErrorInfo(err_info); - init_result.SetFail(); - resp->CopyFrom(init_resp); + std::string err_msg = "init multipart upload failed"; + SetResultAndLogError(init_result, err_msg); if (handler) { - handler->UpdateStatus(TransferStatus::FAILED, init_result); + handler->UpdateStatus(TransferStatus::FAILED); } return init_result; } resume_uploadid = init_resp.GetUploadId(); if (resume_uploadid.empty()) { - std::string err_info = "MultiUploadObject failed, upload id is empty"; - SDK_LOG_ERR("%s", err_info.c_str()); - init_result.SetErrorInfo(err_info); - init_result.SetFail(); - resp->CopyFrom(init_resp); + std::string err_msg = "upload id empty"; + SetResultAndLogError(init_result, err_msg); if (handler) { - handler->UpdateStatus(TransferStatus::FAILED, init_result); + handler->UpdateStatus(TransferStatus::FAILED); } return init_result; } @@ -582,15 +586,13 @@ CosResult ObjectOp::MultiUploadObject(const MultiUploadObjectReq& req, &etags, &part_numbers, handler); // Cancel way if (handler && !handler->ShouldContinue()) { - SDK_LOG_INFO("Multi upload object, canceled"); + SetResultAndLogError(upload_result, "user canceled request"); handler->UpdateStatus(TransferStatus::CANCELED); return upload_result; } // Notice the cancel way not need to abort the uploadid if (!upload_result.IsSucc()) { - SDK_LOG_ERR("MultiUploadObject failed, upload part failed"); - upload_result.SetFail(); // 失败了不abort,再次上传走断点续传 // When copy failed need abort. // AbortMultiUploadReq abort_req(req.GetBucketName(), @@ -605,13 +607,13 @@ CosResult ObjectOp::MultiUploadObject(const MultiUploadObjectReq& req, // return abort_result; // } if (handler) { - handler->UpdateStatus(TransferStatus::FAILED, upload_result); + handler->UpdateStatus(TransferStatus::FAILED); } return upload_result; } // 3. Complete - CosResult complete_result; + CosResult comp_result; CompleteMultiUploadReq comp_req(bucket_name, object_name, resume_uploadid); CompleteMultiUploadResp comp_resp; comp_req.SetConnTimeoutInms(req.GetConnTimeoutInms()); @@ -620,18 +622,9 @@ CosResult ObjectOp::MultiUploadObject(const MultiUploadObjectReq& req, comp_req.SetEtags(etags); comp_req.SetPartNumbers(part_numbers); - complete_result = CompleteMultiUpload(comp_req, &comp_resp); - resp->CopyFrom(comp_resp); - if (handler) { - if (complete_result.IsSucc()) { - handler->UpdateStatus(TransferStatus::COMPLETED, complete_result); - } else { - handler->UpdateStatus(TransferStatus::FAILED, complete_result); - } - } - + comp_result = CompleteMultiUpload(comp_req, &comp_resp); // check crc64 if needed - if (req.CheckCRC64() && complete_result.IsSucc() && + if (req.CheckCRC64() && comp_result.IsSucc() && !comp_resp.GetXCosHashCrc64Ecma().empty()) { uint64_t crc64_origin = 0; #if defined(_WIN32) @@ -646,17 +639,28 @@ CosResult ObjectOp::MultiUploadObject(const MultiUploadObjectReq& req, uint64_t crc64_server_resp = StringUtil::StringToUint64(comp_resp.GetXCosHashCrc64Ecma()); if (crc64_server_resp != crc64_origin) { - std::string err_info = + std::string err_msg = "MultiUploadObject failed, crc64 check failed, crc64_origin: " + std::to_string(crc64_origin) + ", crc64_server_resp: " + std::to_string(crc64_server_resp); - SDK_LOG_ERR("%s", err_info.c_str()); - complete_result.SetErrorInfo(err_info); - complete_result.SetFail(); + SetResultAndLogError(comp_result, err_msg); } } - return complete_result; + if (comp_result.IsSucc()) { + if (handler) { + handler->UpdateStatus(TransferStatus::COMPLETED, comp_result, + comp_resp.GetHeaders(), comp_resp.GetBody()); + } else { + resp->CopyFrom(comp_resp); + } + } else { + if (handler) { + handler->UpdateStatus(TransferStatus::FAILED); + } + } + + return comp_result; } CosResult ObjectOp::InitMultiUpload(const InitMultiUploadReq& req, @@ -685,7 +689,7 @@ CosResult ObjectOp::UploadPartData(const UploadPartDataReq& req, std::istream& is = req.GetStream(); if (is.peek() == EOF) { - result.SetErrorInfo("Input Stream is empty."); + result.SetErrorMsg("Input Stream is empty."); return result; } @@ -716,7 +720,7 @@ CosResult ObjectOp::UploadPartData(const UploadPartDataReq& req, if (result.IsSucc() && is_check_md5 && !StringUtil::IsV4ETag(resp->GetEtag()) && md5_str != resp->GetEtag()) { result.SetFail(); - result.SetErrorInfo("Response etag is not correct, Please try again."); + result.SetErrorMsg("Response etag is not correct, Please try again."); SDK_LOG_ERR( "Response etag is not correct, Please try again. Expect md5 is: %s, " "but return etag is: %s. RequestId: %s", @@ -750,9 +754,8 @@ CosResult ObjectOp::CompleteMultiUpload(const CompleteMultiUploadReq& req, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { CosResult result; - result.SetErrorInfo( - "GenerateCompleteMultiUploadReqBody fail, " - "check your part_numbers and etags."); + result.SetErrorMsg("GenerateCompleteMultiUploadReqBody fail, " + "check your part_numbers and etags."); return result; } @@ -809,7 +812,7 @@ CosResult ObjectOp::PutObjectACL(const PutObjectACLReq& req, headers.find("x-cos-grant-write") == headers.end() && headers.find("x-cos-grant-full-control") == headers.end()) { if (!req.GenerateRequestBody(&req_body)) { - result.SetErrorInfo("Generate PutObjectACL Request Body fail."); + result.SetErrorMsg("Generate PutObjectACL Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -837,7 +840,7 @@ CosResult ObjectOp::Copy(const CopyReq& req, CopyResp* resp) { std::string copy_source = req.GetHeader("x-cos-copy-source"); if (copy_source.empty()) { SDK_LOG_ERR("You must SetXCosCopySource before call Copy."); - result.SetErrorInfo("You must SetXCosCopySource before call Copy."); + result.SetErrorMsg("You must SetXCosCopySource before call Copy."); return result; } std::vector v; @@ -846,7 +849,7 @@ CosResult ObjectOp::Copy(const CopyReq& req, CopyResp* resp) { if (v.size() < 5) { SDK_LOG_ERR("x-cos-copy-source is illegal, source = %s", copy_source.c_str()); - result.SetErrorInfo("Check XCosCopySource."); + result.SetErrorMsg("Check XCosCopySource."); return result; } src_bucket_appid = v[0]; @@ -857,7 +860,7 @@ CosResult ObjectOp::Copy(const CopyReq& req, CopyResp* resp) { if (v.size() < 2) { SDK_LOG_ERR("x-cos-copy-source is illegal, source = %s", copy_source.c_str()); - result.SetErrorInfo("Copy fail, please check XCosCopySource."); + result.SetErrorMsg("Copy fail, please check XCosCopySource."); return result; } src_obj = copy_source.substr(v[0].size()); @@ -889,7 +892,7 @@ CosResult ObjectOp::Copy(const CopyReq& req, CopyResp* resp) { if (!result.IsSucc()) { SDK_LOG_ERR("Get object length before download object fail, req=[%s]", req.DebugString().c_str()); - result.SetErrorInfo("Copy fail, can't get source object length."); + result.SetErrorMsg("Copy fail, can't get source object length."); return result; } @@ -1002,10 +1005,9 @@ CosResult ObjectOp::Copy(const CopyReq& req, CopyResp* resp) { CosResult abort_result = AbortMultiUpload(abort_req, &abort_resp); if (!abort_result.IsSucc()) { - SDK_LOG_ERR( - "Copy failed, and abort muliti upload also failed" - ", upload_id=%s", - upload_id.c_str()); + SDK_LOG_ERR("Copy failed, and abort muliti upload also failed" + ", upload_id=%s", + upload_id.c_str()); return abort_result; } else { SDK_LOG_ERR("Copy failed, abort upload part copy, upload_id=%s", @@ -1014,10 +1016,10 @@ CosResult ObjectOp::Copy(const CopyReq& req, CopyResp* resp) { ret.SetHttpStatus(ptask->GetHttpStatus()); if (ptask->GetHttpStatus() == -1) { - ret.SetErrorInfo(ptask->GetErrMsg()); + ret.SetErrorMsg(ptask->GetErrMsg()); } else if (!ret.ParseFromHttpResponse(task_resp_headers, task_resp)) { - result.SetErrorInfo(task_resp); + result.SetErrorMsg(task_resp); } return ret; } @@ -1050,7 +1052,7 @@ CosResult ObjectOp::Copy(const CopyReq& req, CopyResp* resp) { "Source Object is too large or your upload copy part size in config" "is too small, src obj size=%" PRIu64 ", copy_part_size=%" PRIu64, file_size, CosSysConfig::GetUploadCopyPartSize()); - result.SetErrorInfo( + result.SetErrorMsg( "Could not copy object, because of object size is too large " "or part size is too small."); return result; @@ -1066,7 +1068,7 @@ CosResult ObjectOp::PostObjectRestore(const PostObjectRestoreReq& req, CosResult result; std::string req_body; if (!req.GenerateRequestBody(&req_body)) { - result.SetErrorInfo("Generate PostObjectRestore Request Body fail."); + result.SetErrorMsg("Generate PostObjectRestore Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -1083,16 +1085,20 @@ CosResult ObjectOp::MultiThreadDownload(const MultiGetObjectReq& req, MultiGetObjectResp* resp, const SharedTransferHandler& handler) { CosResult result; + if (!handler && !resp) { + SetResultAndLogError(result, "invalid input parameter"); + return result; + } CosResult head_result; // 1. 调用HeadObject获取文件长度 HeadObjectReq head_req(req.GetBucketName(), req.GetObjectName()); - ; HeadObjectResp head_resp; head_result = HeadObject(head_req, &head_resp); if (!head_result.IsSucc()) { - SDK_LOG_ERR("failed to get object length before downloading object."); + SetResultAndLogError( + head_result, "failed to get object length before downloading object."); if (handler) { - handler->UpdateStatus(TransferStatus::FAILED, head_result); + handler->UpdateStatus(TransferStatus::FAILED); } return head_result; } @@ -1118,10 +1124,10 @@ CosResult ObjectOp::MultiThreadDownload(const MultiGetObjectReq& req, std::string auth_str = AuthTool::Sign(GetAccessKey(), GetSecretKey(), req.GetMethod(), path, headers, params); if (auth_str.empty()) { - result.SetErrorInfo( - "Generate auth str fail, check your access_key/secret_key."); + SetResultAndLogError( + result, "generate auth str failed, check your access_key/secret_key."); if (handler) { - handler->UpdateStatus(TransferStatus::FAILED, result); + handler->UpdateStatus(TransferStatus::FAILED); } return result; } @@ -1139,18 +1145,17 @@ CosResult ObjectOp::MultiThreadDownload(const MultiGetObjectReq& req, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); #endif if (-1 == fd) { - std::string err_info = "open file(" + local_path + - ") fail, errno=" + StringUtil::IntToString(errno); - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + std::string err_msg = "open file(" + local_path + + ") fail, errno=" + StringUtil::IntToString(errno); + SetResultAndLogError(result, err_msg); if (handler) { - handler->UpdateStatus(TransferStatus::FAILED, result); + handler->UpdateStatus(TransferStatus::FAILED); } return result; } // 4. 多线程下载 - std::string objecdt_etag = head_resp.GetEtag(); + std::string object_etag = head_resp.GetEtag(); uint64_t file_size = head_resp.GetContentLength(); if (handler) { handler->SetTotalSize(file_size); @@ -1192,10 +1197,11 @@ CosResult ObjectOp::MultiThreadDownload(const MultiGetObjectReq& req, // TODO(jackyding) 暂时不校验md5或crc,分块上传的文件etag不是md5 // Poco::MD5Engine md5_engine; + MultiGetObjectResp get_resp; while (offset < file_size) { if (handler && !handler->ShouldContinue()) { task_fail_flag = true; - result.SetErrorInfo("FileUpload handler canceled"); + SetResultAndLogError(result, "user canceled request"); break; } SDK_LOG_DBG("down data, offset=%" PRIu64 ", file_size=%" PRIu64, offset, @@ -1232,13 +1238,12 @@ CosResult ObjectOp::MultiThreadDownload(const MultiGetObjectReq& req, SDK_LOG_ERR("down data, down task fail, rsp:%s", task_resp.c_str()); result.SetHttpStatus(ptask->GetHttpStatus()); if (ptask->GetHttpStatus() == -1) { - result.SetErrorInfo(ptask->GetErrMsg()); + result.SetErrorMsg(ptask->GetErrMsg()); } else if (!result.ParseFromHttpResponse(task_resp_headers, task_resp)) { - result.SetErrorInfo(task_resp); + result.SetErrorMsg(task_resp); } - resp->ParseFromHeaders(ptask->GetRespHeaders()); - + // resp->ParseFromHeaders(ptask->GetRespHeaders()); task_fail_flag = true; break; } else { @@ -1247,22 +1252,20 @@ CosResult ObjectOp::MultiThreadDownload(const MultiGetObjectReq& req, #else if (-1 == lseek(fd, vec_offset[task_index], SEEK_SET)) { #endif - std::string err_info = - "down data, lseek ret=" + StringUtil::IntToString(errno) + + std::string err_msg = + "down data, lseek failed, ret=" + StringUtil::IntToString(errno) + ", offset=" + StringUtil::Uint64ToString(vec_offset[task_index]); - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + SetResultAndLogError(result, err_msg); task_fail_flag = true; break; } if (-1 == write(fd, file_content_buf[task_index], ptask->GetDownLoadLen())) { - std::string err_info = - "down data, write ret=" + StringUtil::IntToString(errno) + + std::string err_msg = + "down data, write failed, ret=" + StringUtil::IntToString(errno) + ", len=" + StringUtil::Uint64ToString(ptask->GetDownLoadLen()); - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + SetResultAndLogError(result, err_msg); task_fail_flag = true; break; } @@ -1275,14 +1278,13 @@ CosResult ObjectOp::MultiThreadDownload(const MultiGetObjectReq& req, if (!is_header_set) { std::map resp_headers = ptask->GetRespHeaders(); - resp->ParseFromHeaders(resp_headers); + get_resp.ParseFromHeaders(resp_headers); is_header_set = true; } - SDK_LOG_DBG( - "down data, down_times=%u, task_index=%d, file_size=%lu, " - "offset=%lu, downlen:%lu ", - down_times, task_index, file_size, vec_offset[task_index], - ptask->GetDownLoadLen()); + SDK_LOG_DBG("down data, down_times=%u, task_index=%d, file_size=%lu, " + "offset=%lu, downlen:%lu ", + down_times, task_index, file_size, vec_offset[task_index], + ptask->GetDownLoadLen()); } } @@ -1300,20 +1302,17 @@ CosResult ObjectOp::MultiThreadDownload(const MultiGetObjectReq& req, if (!task_fail_flag) { SDK_LOG_INFO("down data succeed"); - result.SetSucc(); - // 下载成功则用head得到的content_length和etag设置get response - resp->SetContentLength(file_size); - resp->SetEtag(objecdt_etag); if (handler) { - handler->UpdateStatus(TransferStatus::COMPLETED, result); + handler->UpdateStatus(TransferStatus::COMPLETED, result, + get_resp.GetHeaders()); + } else { + *resp = get_resp; } } else { - SDK_LOG_INFO("down data failed"); - - result.SetFail(); + SetResultAndLogError(result, "download data failed"); if (handler) { - handler->UpdateStatus(TransferStatus::FAILED, result); + handler->UpdateStatus(TransferStatus::FAILED); } } @@ -1332,7 +1331,7 @@ CosResult ObjectOp::MultiThreadDownload(const MultiGetObjectReq& req, } CosResult ObjectOp::MultiThreadUpload( - const MultiUploadObjectReq& req, const std::string& upload_id, + const MultiPutObjectReq& req, const std::string& upload_id, const std::vector& already_exist_parts, bool resume_flag, std::vector* etags_ptr, std::vector* part_numbers_ptr, @@ -1355,13 +1354,10 @@ CosResult ObjectOp::MultiThreadUpload( fin.open(req.GetLocalFilePath(), std::ios::in | std::ios::binary); #endif if (!fin) { - std::string err_info = "MultiThreadUpload failed, failed to open file: " + - req.GetLocalFilePath(); - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); - result.SetFail(); + std::string err_msg = "failed to open file: " + req.GetLocalFilePath(); + SetResultAndLogError(result, err_msg); if (handler) { - handler->UpdateStatus(TransferStatus::FAILED, result); + handler->UpdateStatus(TransferStatus::FAILED); } return result; } @@ -1393,13 +1389,12 @@ CosResult ObjectOp::MultiThreadUpload( } if (part_number > kMaxPartNumbers) { - std::string err_info = "MultiThreadUpload failed, part number: " + - std::to_string(part_number) + " larger than 10000"; - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); - result.SetFail(); + std::string err_msg = + "upload failed, part number: " + std::to_string(part_number) + + " larger than 10000"; + SetResultAndLogError(result, err_msg); if (handler) { - handler->UpdateStatus(TransferStatus::FAILED, result); + handler->UpdateStatus(TransferStatus::FAILED); } return result; } @@ -1430,7 +1425,7 @@ CosResult ObjectOp::MultiThreadUpload( int task_index = 0; if (handler && !handler->ShouldContinue()) { task_fail_flag = true; - result.SetErrorInfo("FileUpload handler canceled"); + result.SetErrorMsg("user canceled request"); break; } @@ -1457,7 +1452,8 @@ CosResult ObjectOp::MultiThreadUpload( already_exist_parts[part_number].c_str()); ptask->SetTaskSuccess(); SDK_LOG_INFO("upload data part:%" PRIu64 " has resumed", part_number); - if (handler) handler->UpdateProgress(read_len); + if (handler) + handler->UpdateProgress(read_len); } else { FillUploadTask(upload_id, host, path, file_content_buf[task_index], read_len, part_number, ptask); @@ -1483,10 +1479,10 @@ CosResult ObjectOp::MultiThreadUpload( task_resp.c_str()); result.SetHttpStatus(ptask->GetHttpStatus()); if (ptask->GetHttpStatus() == -1) { - result.SetErrorInfo(ptask->GetErrMsg()); + result.SetErrorMsg(ptask->GetErrMsg()); } else if (!result.ParseFromHttpResponse(task_resp_headers, task_resp)) { - result.SetErrorInfo(task_resp); + result.SetErrorMsg(task_resp); } task_fail_flag = true; @@ -1503,11 +1499,8 @@ CosResult ObjectOp::MultiThreadUpload( } else if (ptask->IsResume() && !ptask->GetResumeEtag().empty()) { etags_ptr->push_back(ptask->GetResumeEtag()); } else { - std::string err_info = - "upload data, upload task succ, but response header missing etag " - "field."; - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + std::string err_msg = "upload failed response header missing etag"; + SetResultAndLogError(result, err_msg); result.SetHttpStatus(ptask->GetHttpStatus()); task_fail_flag = true; break; @@ -1670,7 +1663,7 @@ CosResult ObjectOp::SelectObjectContent(const SelectObjectContentReq& req, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { - result.SetErrorInfo("Generate PostObjectRestore Request Body fail."); + result.SetErrorMsg("Generate PostObjectRestore Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -1698,7 +1691,7 @@ CosResult ObjectOp::PutLiveChannel(const PutLiveChannelReq& req, std::string req_body; if (!req.GenerateRequestBody(&req_body)) { - result.SetErrorInfo("Generate PutLiveChannel Request Body fail."); + result.SetErrorMsg("Generate PutLiveChannel Request Body fail."); return result; } std::string raw_md5 = CodecUtil::Base64Encode(CodecUtil::RawMd5(req_body)); @@ -1764,9 +1757,9 @@ CosResult ObjectOp::DeleteLiveChannel(const DeleteLiveChannelReq& req, std::map(), "", false, resp); } -CosResult ObjectOp::GetLiveChannelVodPlaylist( - const GetLiveChannelVodPlaylistReq& req, - GetLiveChannelVodPlaylistResp* resp) { +CosResult +ObjectOp::GetLiveChannelVodPlaylist(const GetLiveChannelVodPlaylistReq& req, + GetLiveChannelVodPlaylistResp* resp) { std::string host = CosSysConfig::GetHost(GetAppId(), m_config->GetRegion(), req.GetBucketName()); std::string path = req.GetPath(); @@ -1774,9 +1767,9 @@ CosResult ObjectOp::GetLiveChannelVodPlaylist( std::map(), "", false, resp); } -CosResult ObjectOp::PostLiveChannelVodPlaylist( - const PostLiveChannelVodPlaylistReq& req, - PostLiveChannelVodPlaylistResp* resp) { +CosResult +ObjectOp::PostLiveChannelVodPlaylist(const PostLiveChannelVodPlaylistReq& req, + PostLiveChannelVodPlaylistResp* resp) { std::string host = CosSysConfig::GetHost(GetAppId(), m_config->GetRegion(), req.GetBucketName()); std::string path = req.GetPath(); @@ -1853,7 +1846,7 @@ CosResult ObjectOp::ResumableGetObject(const MultiGetObjectReq& req, std::string auth_str = AuthTool::Sign(GetAccessKey(), GetSecretKey(), req.GetMethod(), path, headers, params); if (auth_str.empty()) { - result.SetErrorInfo( + result.SetErrorMsg( "Generate auth str fail, check your access_key/secret_key."); return result; } @@ -1891,10 +1884,10 @@ CosResult ObjectOp::ResumableGetObject(const MultiGetObjectReq& req, } if (-1 == fd) { - std::string err_info = "open file(" + local_path + - ") fail, errno=" + StringUtil::IntToString(errno); - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + std::string err_msg = "open file(" + local_path + + ") fail, errno=" + StringUtil::IntToString(errno); + SDK_LOG_ERR("%s", err_msg.c_str()); + result.SetErrorMsg(err_msg); return result; } @@ -1973,10 +1966,10 @@ CosResult ObjectOp::ResumableGetObject(const MultiGetObjectReq& req, SDK_LOG_ERR("down data, down task fail, rsp: %s", task_resp.c_str()); result.SetHttpStatus(ptask->GetHttpStatus()); if (ptask->GetHttpStatus() == -1) { - result.SetErrorInfo(ptask->GetErrMsg()); + result.SetErrorMsg(ptask->GetErrMsg()); } else if (!result.ParseFromHttpResponse(task_resp_headers, task_resp)) { - result.SetErrorInfo(task_resp); + result.SetErrorMsg(task_resp); } resp->ParseFromHeaders(ptask->GetRespHeaders()); @@ -1984,22 +1977,22 @@ CosResult ObjectOp::ResumableGetObject(const MultiGetObjectReq& req, break; } else { if (-1 == lseek(fd, vec_offset[task_index], SEEK_SET)) { - std::string err_info = + std::string err_msg = "down data, lseek ret=" + StringUtil::IntToString(errno) + ", offset=" + StringUtil::Uint64ToString(vec_offset[task_index]); - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + SDK_LOG_ERR("%s", err_msg.c_str()); + result.SetErrorMsg(err_msg); task_fail_flag = true; break; } if (-1 == write(fd, file_content_buf[task_index], ptask->GetDownLoadLen())) { - std::string err_info = + std::string err_msg = "down data, write ret=" + StringUtil::IntToString(errno) + ", len=" + StringUtil::Uint64ToString(ptask->GetDownLoadLen()); - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + SDK_LOG_ERR("%s", err_msg.c_str()); + result.SetErrorMsg(err_msg); task_fail_flag = true; break; } @@ -2106,9 +2099,9 @@ CosResult ObjectOp::PutObjects(const PutObjectsByDirectoryReq& req, CosResult result; std::string directory_name = req.GetDirectoryName(); if (directory_name.empty() || !FileUtil::IsDirectoryExists(directory_name)) { - std::string err_info = "directory :" + directory_name + " not exists"; - SDK_LOG_ERR("%s", err_info.c_str()); - result.SetErrorInfo(err_info); + std::string err_msg = "directory :" + directory_name + " not exists"; + SDK_LOG_ERR("%s", err_msg.c_str()); + result.SetErrorMsg(err_msg); return result; } @@ -2227,9 +2220,9 @@ CosResult ObjectOp::GetQRcode(const GetQRcodeReq& req, GetQRcodeResp* resp) { return NormalAction(host, path, req, "", false, resp); } -CosResult ObjectOp::DescribeDocProcessBuckets( - const DescribeDocProcessBucketsReq& req, - DescribeDocProcessBucketsResp* resp) { +CosResult +ObjectOp::DescribeDocProcessBuckets(const DescribeDocProcessBucketsReq& req, + DescribeDocProcessBucketsResp* resp) { std::string host = "ci." + m_config->GetRegion() + ".myqcloud.com"; std::string path = req.GetPath(); return NormalAction(host, path, req, "", false, resp); @@ -2243,8 +2236,8 @@ CosResult ObjectOp::DocPreview(const DocPreviewReq& req, DocPreviewResp* resp) { std::ofstream ofs(req.GetLocalFilePath().c_str(), std::ios::out | std::ios::binary | std::ios::trunc); if (!ofs.is_open()) { - result.SetErrorInfo("Open local file fail, local file=" + - req.GetLocalFilePath()); + result.SetErrorMsg("Open local file fail, local file=" + + req.GetLocalFilePath()); return result; } result = DownloadAction(host, path, req, resp, ofs); diff --git a/src/response/base_resp.cpp b/src/response/base_resp.cpp index 59c719f..46e7b57 100644 --- a/src/response/base_resp.cpp +++ b/src/response/base_resp.cpp @@ -44,6 +44,11 @@ void BaseResp::ParseFromHeaders( m_content_length = StringUtil::StringToUint64(itr->second); } + itr = headers.find(kHttpHeaderContentRange); + if (headers.end() != itr) { + m_content_range = StringUtil::StringToUint64(itr->second); + } + itr = headers.find(kHttpHeaderContentType); if (headers.end() != itr) { m_content_type = itr->second; @@ -216,24 +221,24 @@ bool BaseResp::ParseFromACLXMLString(const std::string& body, } void BaseResp::InternalCopyFrom(const BaseResp& resp) { - SetContentLength(resp.GetContentLength()); - SetContentType(resp.GetContentType()); - SetEtag(resp.GetEtag()); - SetConnection(resp.GetConnection()); - SetDate(resp.GetDate()); - SetServer(resp.GetServer()); - SetContentDisposition(resp.GetContentDisposition()); - SetContentEncoding(resp.GetContentEncoding()); - SetCacheControl(resp.GetCacheControl()); - SetExpires(resp.GetExpires()); - SetXCosRequestId(resp.GetXCosRequestId()); - SetXCosTraceId(resp.GetXCosTraceId()); - SetXCosStorageTier(resp.GetXCosStorageTier()); - SetXCosStorageClass(resp.GetXCosStorageClass()); - SetXCosHashCrc64Ecma(resp.GetXCosHashCrc64Ecma()); - SetLastModified(resp.GetLastModified()); - SetHeaders(resp.GetHeaders()); - SetBody(resp.GetBody()); + m_headers = resp.m_headers; + m_body_str = resp.m_body_str; + m_content_length = resp.m_content_length; + m_content_type = resp.m_content_type; + m_etag = resp.m_etag; + m_connection = resp.m_connection; + m_date = resp.m_date; + m_server = resp.m_server; + m_content_disposition = resp.m_content_disposition; + m_content_encoding = resp.m_content_encoding; + m_cache_control = resp.m_cache_control; + m_expires = resp.m_expires; + m_last_modified = resp.m_last_modified; + m_x_cos_request_id = resp.m_x_cos_request_id; + m_x_cos_trace_id = resp.m_x_cos_trace_id; + m_x_cos_storage_tier = resp.m_x_cos_storage_tier; + m_x_cos_storage_class = resp.m_x_cos_storage_class; + m_x_cos_hash_crc64ecma = resp.m_x_cos_hash_crc64ecma; } } // namespace qcloud_cos diff --git a/src/response/object_resp.cpp b/src/response/object_resp.cpp index 94aa773..2cb38c6 100644 --- a/src/response/object_resp.cpp +++ b/src/response/object_resp.cpp @@ -73,7 +73,8 @@ bool CompleteMultiUploadResp::ParseFromXmlString(const std::string& body) { rapidxml::xml_node<>* root = doc.first_node(kCompleteMultiUploadRoot.c_str()); if (NULL == root) { - SDK_LOG_ERR("Miss root node=ListBucketsResult, xml_body=%s", body.c_str()); + SDK_LOG_ERR("Miss root node=CompleteMultipartUploadResult, xml_body=%s", + body.c_str()); delete[] cstr; return false; } @@ -96,6 +97,37 @@ bool CompleteMultiUploadResp::ParseFromXmlString(const std::string& body) { return true; } +bool MultiPutObjectResp::ParseFromXmlString(const std::string& body) { + std::string tmp_body = body; + rapidxml::xml_document<> doc; + if (!StringUtil::StringToXml(&tmp_body[0], &doc)) { + SDK_LOG_ERR("Parse string to xml doc error, xml_body=%s", body.c_str()); + return false; + } + + rapidxml::xml_node<>* root = doc.first_node(kCompleteMultiUploadRoot.c_str()); + if (NULL == root) { + SDK_LOG_ERR("Miss root node=CompleteMultipartUploadResult, xml_body=%s", + body.c_str()); + return false; + } + + rapidxml::xml_node<>* node = root->first_node(); + for (; node != NULL; node = node->next_sibling()) { + const std::string& node_name = node->name(); + if (node_name == kCompleteMultiUploadLocation) { + m_location = node->value(); + } else if (node_name == kCompleteMultiUploadBucket) { + m_bucket = node->value(); + } else if (node_name == kCompleteMultiUploadKey) { + m_key = node->value(); + } else if (node_name == kCompleteMultiUploadETag) { + SetEtag(StringUtil::Trim(node->value(), "\"")); + } + } + return true; +} + void GetObjectResp::ParseFromHeaders( const std::map& headers) { BaseResp::ParseFromHeaders(headers); @@ -129,7 +161,7 @@ void HeadObjectResp::ParseFromHeaders( } } -void MultiUploadObjectResp::CopyFrom(const InitMultiUploadResp& resp) { +void MultiPutObjectResp::CopyFrom(const InitMultiUploadResp& resp) { m_resp_tag = "Init"; InternalCopyFrom(resp); m_upload_id = resp.GetUploadId(); @@ -138,12 +170,12 @@ void MultiUploadObjectResp::CopyFrom(const InitMultiUploadResp& resp) { } // TODO(sevenyou) -void MultiUploadObjectResp::CopyFrom(const UploadPartDataResp& resp) { +void MultiPutObjectResp::CopyFrom(const UploadPartDataResp& resp) { m_resp_tag = "Upload"; InternalCopyFrom(resp); } -void MultiUploadObjectResp::CopyFrom(const CompleteMultiUploadResp& resp) { +void MultiPutObjectResp::CopyFrom(const CompleteMultiUploadResp& resp) { m_resp_tag = "Complete"; InternalCopyFrom(resp); m_location = resp.GetLocation(); diff --git a/src/trsf/transfer_handler.cpp b/src/trsf/transfer_handler.cpp index 7d8de23..1e7c1ea 100644 --- a/src/trsf/transfer_handler.cpp +++ b/src/trsf/transfer_handler.cpp @@ -1,9 +1,9 @@ #include "trsf/transfer_handler.h" - -#include - #include "Poco/Buffer.h" #include "Poco/StreamCopier.h" +#include "response/object_resp.h" +#include "trsf/async_context.h" +#include namespace qcloud_cos { PartState::PartState() @@ -18,18 +18,17 @@ PartState::PartState(int part_num, std::string& etag, size_t size, TransferHandler::TransferHandler(const std::string& bucket_name, const std::string& object_name, - uint64_t total_size, const std::string& file_path) : m_bucket_name(bucket_name), m_object_name(object_name), m_local_file_path(file_path), - m_total_size(total_size), + m_total_size(0), m_current_progress(0), m_status(TransferStatus::NOT_START), m_uploadid(""), m_cancel(false), m_progress_cb(NULL), - m_status_cb(NULL), + m_done_cb(NULL), m_user_data(NULL) {} static std::string GetNameForStatus(TransferStatus status) { @@ -47,7 +46,7 @@ static std::string GetNameForStatus(TransferStatus status) { case TransferStatus::ABORTED: return "ABORTED"; default: - return "UNKNOWN"; + return "UNKNOWN"; } } @@ -102,6 +101,12 @@ bool TransferHandler::IsAllowTransition(TransferStatus org, } void TransferHandler::UpdateStatus(const TransferStatus& status) { + // 必须先调done回调 + if (m_done_cb && IsFinishStatus(status)) { + SharedAsyncContext context(new AsyncContext(shared_from_this())); + m_done_cb(context, m_user_data); + } + { std::unique_lock locker(m_lock_stat); if (IsAllowTransition(m_status, status)) { @@ -116,11 +121,6 @@ void TransferHandler::UpdateStatus(const TransferStatus& status) { } } } - - // trigger status callback - if (m_status_cb) { - m_status_cb(GetNameForStatus(m_status), m_user_data); - } } void TransferHandler::UpdateStatus(const TransferStatus& status, @@ -129,6 +129,29 @@ void TransferHandler::UpdateStatus(const TransferStatus& status, UpdateStatus(status); } +void TransferHandler::UpdateStatus( + const TransferStatus& status, const CosResult& result, + const std::map headers, const std::string& body) { + // 先更新result,header和body + m_result = result; + m_resp_headers = headers; + m_resp_body = body; + UpdateStatus(status); +} + +MultiPutObjectResp TransferHandler::GetMultiPutObjectResp() const { + MultiPutObjectResp resp; + resp.ParseFromHeaders(m_resp_headers); + resp.ParseFromXmlString(m_resp_body); + return resp; +} + +MultiGetObjectResp TransferHandler::GetMultiGetObjectResp() const { + MultiGetObjectResp resp; + resp.ParseFromHeaders(m_resp_headers); + return resp; +} + TransferStatus TransferHandler::GetStatus() const { std::lock_guard locker(m_lock_stat); return m_status; @@ -155,9 +178,10 @@ std::string TransferHandler::GetStatusString() const { return GetNameForStatus(m_status); } -std::streamsize HandleStreamCopier::handleCopyStream( - const SharedTransferHandler& handler, std::istream& istr, - std::ostream& ostr, std::size_t bufferSize) { +std::streamsize +HandleStreamCopier::handleCopyStream(const SharedTransferHandler& handler, + std::istream& istr, std::ostream& ostr, + std::size_t bufferSize) { poco_assert(bufferSize > 0); Poco::Buffer buffer(bufferSize); diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 530bbe6..531b471 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -7,6 +7,7 @@ file(GLOB util_test_src src/util_test.cpp) file(GLOB object_op_test_src src/object_op_test.cpp) file(GLOB bucket_op_test_src src/bucket_op_test.cpp) file(GLOB live_channel_test_src src/live_channel_test.cpp) +file(GLOB async_op_test_src src/async_op_test.cpp) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) link_directories(${POCO_LINK_DIR} ${GTEST_LINK_DIR}) #这一行要放到add_executable前面 @@ -29,6 +30,8 @@ target_link_libraries(bucket-op-test cossdk ${POCO_LIBS} ${SYSTEM_LIBS} ${GTEST_ add_executable(live-channel-test ${live_channel_test_src} ${common_src}) target_link_libraries(live-channel-test cossdk ${POCO_LIBS} ${SYSTEM_LIBS} ${GTEST_LIBS}) +add_executable(async-op-test ${async_op_test_src} ${common_src}) +target_link_libraries(async-op-test cossdk ${POCO_LIBS} ${SYSTEM_LIBS} ${GTEST_LIBS}) # coverage option set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") @@ -40,6 +43,7 @@ add_executable(all-test ${object_op_test_src} ${bucket_op_test_src} ${live_channel_test_src} + ${async_op_test_src} ${common_src}) target_link_libraries(all-test cossdk ${POCO_LIBS} ${SYSTEM_LIBS} ${GTEST_LIBS}) diff --git a/unittest/src/async_op_test.cpp b/unittest/src/async_op_test.cpp new file mode 100644 index 0000000..2964d6e --- /dev/null +++ b/unittest/src/async_op_test.cpp @@ -0,0 +1,584 @@ +#include "cos_api.h" +#include "test_utils.h" +#include "util/file_util.h" +#include "util/simple_dns_cache.h" +#include "gtest/gtest.h" +#include +#include +#include +/* +export CPP_SDK_V5_ACCESS_KEY=xxx +export CPP_SDK_V5_SECRET_KEY=xxx +export CPP_SDK_V5_REGION=ap-guangzhou +export CPP_SDK_V5_UIN=xxx +export CPP_SDK_V5_APPID=xxx +export COS_CPP_V5_TAG="" +export COS_CPP_V5_USE_DNS_CACHE="true" +*/ + +namespace qcloud_cos { + +class AsyncOpTest : public testing::Test { + protected: + static void SetUpTestCase() { + std::cout << "================SetUpTestCase Begin====================" + << std::endl; + m_config = new CosConfig("./config.json"); + m_config->SetAccessKey(GetEnvVar("CPP_SDK_V5_ACCESS_KEY")); + m_config->SetSecretKey(GetEnvVar("CPP_SDK_V5_SECRET_KEY")); + m_config->SetRegion(GetEnvVar("CPP_SDK_V5_REGION")); + if (GetEnvVar("COS_CPP_V5_USE_DNS_CACHE") == "true") { + std::cout << "================USE DNS CACHE====================" + << std::endl; + CosSysConfig::SetUseDnsCache(true); + } + m_client = new CosAPI(*m_config); + + m_bucket_name = "coscppsdkv5ut" + GetEnvVar("COS_CPP_V5_TAG") + "-" + + GetEnvVar("CPP_SDK_V5_APPID"); + { + PutBucketReq req(m_bucket_name); + PutBucketResp resp; + CosResult result = m_client->PutBucket(req, &resp); + ASSERT_TRUE(result.IsSucc()); + } + + std::cout << "================SetUpTestCase End====================" + << std::endl; + } + + static void TearDownTestCase() { + std::cout << "================TearDownTestCase Begin====================" + << std::endl; + + // 1. 删除所有Object + { + GetBucketReq req(m_bucket_name); + GetBucketResp resp; + CosResult result = m_client->GetBucket(req, &resp); + ASSERT_TRUE(result.IsSucc()); + + const std::vector& contents = resp.GetContents(); + for (std::vector::const_iterator c_itr = contents.begin(); + c_itr != contents.end(); ++c_itr) { + const Content& content = *c_itr; + DeleteObjectReq del_req(m_bucket_name, content.m_key); + DeleteObjectResp del_resp; + CosResult del_result = m_client->DeleteObject(del_req, &del_resp); + EXPECT_TRUE(del_result.IsSucc()); + if (!del_result.IsSucc()) { + std::cout << "DeleteObject Failed, check object=" << content.m_key + << std::endl; + } + } + } + + { + // 删除所有碎片 + std::vector bucket_v = {m_bucket_name}; + for (auto& bucket : bucket_v) { + qcloud_cos::ListMultipartUploadReq list_mp_req(bucket); + qcloud_cos::ListMultipartUploadResp list_mp_resp; + qcloud_cos::CosResult list_mp_result = + m_client->ListMultipartUpload(list_mp_req, &list_mp_resp); + ASSERT_TRUE(list_mp_result.IsSucc()); + std::vector rst = list_mp_resp.GetUpload(); + for (std::vector::const_iterator itr = rst.begin(); + itr != rst.end(); ++itr) { + AbortMultiUploadReq abort_mp_req(bucket, itr->m_key, itr->m_uploadid); + AbortMultiUploadResp abort_mp_resp; + CosResult abort_mp_result = + m_client->AbortMultiUpload(abort_mp_req, &abort_mp_resp); + EXPECT_TRUE(abort_mp_result.IsSucc()); + if (!abort_mp_result.IsSucc()) { + std::cout << "AbortMultiUpload Failed, object=" << itr->m_key + << ", upload_id=" << itr->m_uploadid << std::endl; + } + } + } + } + + // 3. 删除Bucket + { + { + DeleteBucketReq req(m_bucket_name); + DeleteBucketResp resp; + CosResult result = m_client->DeleteBucket(req, &resp); + ASSERT_TRUE(result.IsSucc()); + } + } + + delete m_client; + delete m_config; + std::cout << "================TearDownTestCase End====================" + << std::endl; + } // namespace qcloud_cos + + protected: + static CosConfig* m_config; + static CosAPI* m_client; + static std::string m_bucket_name; +}; + +std::string AsyncOpTest::m_bucket_name = ""; +CosConfig* AsyncOpTest::m_config = NULL; +CosAPI* AsyncOpTest::m_client = NULL; + +TEST_F(AsyncOpTest, AsyncOpWithoutCallback) { + std::vector base_size_v = { + 1, 5, 35, 356, 1111, 2545, 25678, 1024 * 1024, 5 * 1024 * 1024}; + for (auto& size : base_size_v) { + for (int i = 1; i < 3; i++) { + std::cout << "base_size: " << size << ", test_time: " << i << std::endl; + + size_t file_size = ((rand() % 100) + 1) * size; + std::string object_name = "test_async_" + std::to_string(file_size); + std::string local_file = "./" + object_name; + + std::cout << "generate file: " << local_file << std::endl; + TestUtils::WriteRandomDatatoFile(local_file, file_size); + + uint64_t file_crc64_origin = FileUtil::GetFileCrc64(local_file); + std::string file_md5_origin = FileUtil::GetFileMd5(local_file); + + std::cout << "file_crc64_origin: " << file_crc64_origin << std::endl; + std::cout << "file_md5_origin: " << file_md5_origin << std::endl; + + // 异步上传 + qcloud_cos::MultiPutObjectReq put_req(m_bucket_name, object_name, + local_file); + std::cout << "async upload object: " << object_name + << ", size: " << file_size << std::endl; + // 开始上传 + SharedAsyncContext context = m_client->PutObjectAsync(put_req); + // 等待上传结束 + context->WaitUntilFinish(); + ASSERT_TRUE(context->GetResult().IsSucc()); + ASSERT_TRUE(!context->GetResult().GetXCosRequestId().empty()); + ASSERT_EQ(context->GetMultiPutObjectResp().GetXCosHashCrc64Ecma(), + std::to_string(file_crc64_origin)); + ASSERT_EQ(context->GetMultiPutObjectResp().GetServer(), "tencent-cos"); + ASSERT_TRUE(!context->GetMultiPutObjectResp().GetDate().empty()); + ASSERT_TRUE(!context->GetMultiPutObjectResp().GetContentType().empty()); + + // 下载 + std::string local_file_download = local_file + "_download"; + + qcloud_cos::MultiGetObjectReq get_req(m_bucket_name, object_name, + local_file_download); + std::cout << "async download object: " << object_name << std::endl; + + // 开始下载 + context = m_client->GetObjectAsync(get_req); + + // 等待下载结束 + context->WaitUntilFinish(); + ASSERT_TRUE(context->GetResult().IsSucc()); + ASSERT_EQ(context->GetMultiGetObjectResp().GetXCosHashCrc64Ecma(), + std::to_string(file_crc64_origin)); + ASSERT_EQ(context->GetMultiGetObjectResp().GetServer(), "tencent-cos"); + ASSERT_TRUE(context->GetMultiGetObjectResp().GetContentLength() > 0); + ASSERT_TRUE(!context->GetMultiGetObjectResp().GetDate().empty()); + ASSERT_TRUE(!context->GetMultiGetObjectResp().GetLastModified().empty()); + ASSERT_TRUE(!context->GetMultiGetObjectResp().GetXCosRequestId().empty()); + ASSERT_TRUE(!context->GetMultiGetObjectResp().GetEtag().empty()); + ASSERT_TRUE(!context->GetMultiGetObjectResp().GetContentRange().empty()); + + // 校验下载下来的文件 + std::string file_md5_download = + TestUtils::CalcFileMd5(local_file_download); + ASSERT_EQ(file_md5_download, file_md5_origin); + + // 删除对象 + CosResult del_result; + qcloud_cos::DeleteObjectReq del_req(m_bucket_name, object_name); + qcloud_cos::DeleteObjectResp del_resp; + del_result = m_client->DeleteObject(del_req, &del_resp); + ASSERT_TRUE(del_result.IsSucc()); + ASSERT_TRUE(!del_result.GetXCosRequestId().empty()); + ASSERT_EQ(del_resp.GetServer(), "tencent-cos"); + ASSERT_TRUE(!del_resp.GetDate().empty()); + // 删除本地文件 + TestUtils::RemoveFile(local_file); + TestUtils::RemoveFile(local_file_download); + } + } +} + +TEST_F(AsyncOpTest, AsyncOpWithProgressCallback) { + std::vector base_size_v = { + 1, 5, 35, 356, 1024, 2545, 25678, 1024 * 1024, 5 * 1024 * 1024}; + for (auto& size : base_size_v) { + for (int i = 1; i < 3; i++) { + std::cout << "base_size: " << size << ", test_time: " << i << std::endl; + + size_t file_size = ((rand() % 100) + 1) * size; + std::string object_name = "test_async_" + std::to_string(file_size); + std::string local_file = "./" + object_name; + + std::cout << "generate file: " << local_file << std::endl; + TestUtils::WriteRandomDatatoFile(local_file, file_size); + + uint64_t file_crc64_origin = FileUtil::GetFileCrc64(local_file); + std::string file_md5_origin = FileUtil::GetFileMd5(local_file); + + std::cout << "file_crc64_origin: " << file_crc64_origin << std::endl; + std::cout << "file_md5_origin: " << file_md5_origin << std::endl; + + FileInfo file_info = { + object_name, local_file, local_file + "_download", + file_size, file_crc64_origin, file_md5_origin}; + + // 异步上传 + qcloud_cos::MultiPutObjectReq put_req(m_bucket_name, object_name, + local_file); + put_req.SetRecvTimeoutInms(1000 * 200); + + auto process_cb = [](uint64_t transferred_size, uint64_t total_size, + void* user_data) { + FileInfo* file_info = reinterpret_cast(user_data); + ASSERT_TRUE(transferred_size <= total_size); + ASSERT_EQ(total_size, file_info->m_file_size); + }; + + std::cout << "async upload object: " << object_name + << ", size: " << file_size << std::endl; + // 设置上传进度回调 + put_req.SetTransferProgressCallback(process_cb); + // 设置私有数据 + put_req.SetUserData(reinterpret_cast(&file_info)); + + // 开始上传 + SharedAsyncContext context = m_client->PutObjectAsync(put_req); + // 等待上传结束 + context->WaitUntilFinish(); + ASSERT_TRUE(context->GetResult().IsSucc()); + ASSERT_EQ(context->GetMultiPutObjectResp().GetXCosHashCrc64Ecma(), + std::to_string(file_info.m_file_crc64_origin)); + + std::string local_file_download = local_file + "_download"; + + qcloud_cos::MultiGetObjectReq get_req(m_bucket_name, object_name, + local_file_download); + // 设置进度回调 + get_req.SetTransferProgressCallback(process_cb); + // 设置私有数据 + get_req.SetUserData(reinterpret_cast(&file_info)); + std::cout << "async download object: " << object_name << std::endl; + + // 开始下载 + context = m_client->GetObjectAsync(get_req); + + // 等待下载结束 + context->WaitUntilFinish(); + ASSERT_TRUE(context->GetResult().IsSucc()); + + // 校验下载下来的文件 + std::string file_md5_download = + TestUtils::CalcFileMd5(local_file_download); + ASSERT_EQ(file_md5_download, file_md5_origin); + + // 删除对象 + CosResult del_result; + qcloud_cos::DeleteObjectReq del_req(m_bucket_name, object_name); + qcloud_cos::DeleteObjectResp del_resp; + del_result = m_client->DeleteObject(del_req, &del_resp); + ASSERT_TRUE(del_result.IsSucc()); + + // 删除本地文件 + TestUtils::RemoveFile(local_file); + TestUtils::RemoveFile(local_file_download); + } + } +} + +TEST_F(AsyncOpTest, AsyncOpWithWithDoneCallback) { + std::vector base_size_v = { + 1, 5, 35, 356, 1024, 2545, 25678, 1024 * 1024, 5 * 1024 * 1024}; + for (auto& size : base_size_v) { + for (int i = 1; i < 3; i++) { + std::cout << "base_size: " << size << ", test_time: " << i << std::endl; + + size_t file_size = ((rand() % 100) + 1) * size; + std::string object_name = "test_async_" + std::to_string(file_size); + std::string local_file = "./" + object_name; + + std::cout << "generate file: " << local_file << std::endl; + TestUtils::WriteRandomDatatoFile(local_file, file_size); + + uint64_t file_crc64_origin = FileUtil::GetFileCrc64(local_file); + std::string file_md5_origin = FileUtil::GetFileMd5(local_file); + + std::cout << "file_crc64_origin: " << file_crc64_origin << std::endl; + std::cout << "file_md5_origin: " << file_md5_origin << std::endl; + + FileInfo file_info = { + object_name, local_file, local_file + "_download", + file_size, file_crc64_origin, file_md5_origin}; + + // 异步上传 + qcloud_cos::MultiPutObjectReq put_req(m_bucket_name, object_name, + local_file); + // 完成回调 + auto multi_put_done_cb = [](const SharedAsyncContext& context, + void* user_data) { + ASSERT_TRUE(context->GetResult().IsSucc()); + FileInfo* file_info = reinterpret_cast(user_data); + ASSERT_EQ(context->GetMultiGetObjectResp().GetXCosHashCrc64Ecma(), + std::to_string(file_info->m_file_crc64_origin)); + ASSERT_EQ(context->GetMultiPutObjectResp().GetServer(), "tencent-cos"); + ASSERT_TRUE(!context->GetMultiPutObjectResp().GetDate().empty()); + ASSERT_TRUE(!context->GetMultiPutObjectResp().GetContentType().empty()); + ASSERT_TRUE(!context->GetMultiPutObjectResp().GetEtag().empty()); + }; + + std::cout << "async upload object: " << object_name + << ", size: " << file_size << std::endl; + // 设置上传完成回调 + put_req.SetDoneCallback(multi_put_done_cb); + // 设置私有数据 + put_req.SetUserData(reinterpret_cast(&file_info)); + + // 开始上传 + SharedAsyncContext context = m_client->PutObjectAsync(put_req); + + // 等待上传结束 + context->WaitUntilFinish(); + ASSERT_TRUE(context->GetResult().IsSucc()); + + // 下载 + auto multi_get_done_cb = [](const SharedAsyncContext& context, + void* user_data) { + ASSERT_TRUE(context->GetResult().IsSucc()); + FileInfo* file_info = (reinterpret_cast(user_data)); + MultiGetObjectResp resp = context->GetMultiGetObjectResp(); + ASSERT_EQ(resp.GetXCosHashCrc64Ecma(), + std::to_string(file_info->m_file_crc64_origin)); + // ASSERT_EQ(resp.GetEtag(), file_info->m_file_md5_origin); + ASSERT_EQ(context->GetMultiGetObjectResp().GetServer(), "tencent-cos"); + ASSERT_TRUE(context->GetMultiGetObjectResp().GetContentLength() > 0); + ASSERT_TRUE(!context->GetMultiGetObjectResp().GetDate().empty()); + ASSERT_TRUE( + !context->GetMultiGetObjectResp().GetLastModified().empty()); + ASSERT_TRUE( + !context->GetMultiGetObjectResp().GetXCosRequestId().empty()); + ASSERT_TRUE(!context->GetMultiGetObjectResp().GetEtag().empty()); + ASSERT_TRUE( + !context->GetMultiGetObjectResp().GetContentRange().empty()); + }; + std::string local_file_download = local_file + "_download"; + + qcloud_cos::MultiGetObjectReq get_req(m_bucket_name, object_name, + local_file_download); + // 设置完成回调 + get_req.SetDoneCallback(multi_get_done_cb); + // 设置私有数据 + get_req.SetUserData(reinterpret_cast(&file_info)); + std::cout << "async download object: " << object_name << std::endl; + // 开始下载 + context = m_client->GetObjectAsync(get_req); + + // 等待下载结束 + context->WaitUntilFinish(); + ASSERT_TRUE(context->GetResult().IsSucc()); + + // 校验下载下来的文件 + std::string file_md5_download = + TestUtils::CalcFileMd5(local_file_download); + ASSERT_EQ(file_md5_download, file_md5_origin); + + // 删除对象 + CosResult del_result; + qcloud_cos::DeleteObjectReq del_req(m_bucket_name, object_name); + qcloud_cos::DeleteObjectResp del_resp; + del_result = m_client->DeleteObject(del_req, &del_resp); + ASSERT_TRUE(del_result.IsSucc()); + + // 删除本地文件 + TestUtils::RemoveFile(local_file); + TestUtils::RemoveFile(local_file_download); + } + } +} + +TEST_F(AsyncOpTest, AsyncOpWithConcurrent) { + std::vector base_size_v = { + 1, 5, 35, 356, 1024, 2545, 25678, 1024 * 1024, 5 * 1024 * 1024}; + for (auto& size : base_size_v) { + const int concurrent_size = 5; + std::unordered_map concurrent_objects; + std::list waiting_list; + std::mutex mutex; + std::condition_variable cond; + + // 生成文件 + for (int i = 0; i < concurrent_size; i++) { + size_t file_size = ((rand() % 100) + 1) * size; + std::string object_name = "test_async_" + std::to_string(i); + std::string local_file = "./" + object_name; + std::cout << "generate file: " << local_file << std::endl; + TestUtils::WriteRandomDatatoFile(local_file, file_size); + uint64_t file_crc64_origin = FileUtil::GetFileCrc64(local_file); + std::string file_md5_origin = FileUtil::GetFileMd5(local_file); + FileInfo file_info = { + object_name, local_file, local_file + "_downlaod", + file_size, file_crc64_origin, file_md5_origin}; + concurrent_objects[object_name] = file_info; + waiting_list.push_back(object_name); + } + + // 多个文件异步上传 + DoneCallback multi_put_done_cb; + for (auto& o : concurrent_objects) { + qcloud_cos::MultiPutObjectReq put_req( + m_bucket_name, o.second.m_object_name, o.second.m_local_file); + multi_put_done_cb = [multi_put_done_cb, &mutex, &cond, + &waiting_list](const SharedAsyncContext& context, + void* user_data) { + EXPECT_TRUE(context->GetResult().IsSucc()); + std::unordered_map* concurrent_objects = + reinterpret_cast*>( + user_data); + ASSERT_TRUE(concurrent_objects->count(context->GetObjectName()) == 1); + if (!context->GetResult().IsSucc()) { + std::cout << "failed to uplaod " << context->GetObjectName() + << ", retry..." << std::endl; + // 上传失败,重试 + qcloud_cos::MultiPutObjectReq put_req(context->GetBucketName(), + context->GetObjectName(), + context->GetLocalFilePath()); + // 设置上传完成回调 + put_req.SetDoneCallback(multi_put_done_cb); + // 设置私有数据 + put_req.SetUserData(user_data); + // 开始上传 + m_client->PutObjectAsync(put_req); + } else { + // 上传成功 + std::cout << "succeed to uplaod " << context->GetObjectName() + << std::endl; + MultiPutObjectResp resp = context->GetMultiPutObjectResp(); + ASSERT_EQ( + resp.GetXCosHashCrc64Ecma(), + std::to_string((*concurrent_objects)[context->GetObjectName()] + .m_file_crc64_origin)); + std::unique_lock lock(mutex); + waiting_list.remove(context->GetObjectName()); + cond.notify_one(); + } + }; + // 设置上传完成回调 + put_req.SetDoneCallback(multi_put_done_cb); + // 设置私有数据 + put_req.SetUserData(reinterpret_cast(&concurrent_objects)); + std::cout << "start to uplaod " << o.second.m_object_name << std::endl; + m_client->PutObjectAsync(put_req); + } + + // TODO timeout + while (!waiting_list.empty()) { + std::string waiting_objects; + for (auto& o : waiting_list) { + waiting_objects.append(o).append(" "); + } + std::cout << "waiting for " << waiting_objects << " to complete uploading" + << std::endl; + std::unique_lock lock(mutex); + cond.wait(lock); + } + + std::cout << "succeed to upload all objects" << std::endl; + + // 多个文件异步下载 + for (auto& o : concurrent_objects) { + waiting_list.push_back(o.first); + } + + DoneCallback multi_get_done_cb; + for (auto& o : concurrent_objects) { + multi_get_done_cb = [&multi_get_done_cb, &mutex, &cond, + &waiting_list](const SharedAsyncContext& context, + void* user_data) { + EXPECT_TRUE(context->GetResult().IsSucc()); + std::unordered_map* concurrent_objects = + reinterpret_cast*>( + user_data); + ASSERT_TRUE(concurrent_objects->count(context->GetObjectName()) == 1); + if (!context->GetResult().IsSucc()) { + std::cout << "failed to download " << context->GetObjectName() + << ", retry..." << std::endl; + // 下载失败,重试 + qcloud_cos::MultiGetObjectReq get_req(context->GetBucketName(), + context->GetObjectName(), + context->GetLocalFilePath()); + get_req.SetDoneCallback(multi_get_done_cb); + get_req.SetUserData(user_data); + m_client->GetObjectAsync(get_req); + } else { + // 下载成功 + std::cout << "succeed to download " << context->GetObjectName() + << std::endl; + MultiGetObjectResp resp = context->GetMultiGetObjectResp(); + ASSERT_EQ( + resp.GetXCosHashCrc64Ecma(), + std::to_string((*concurrent_objects)[context->GetObjectName()] + .m_file_crc64_origin)); + std::unique_lock lock(mutex); + waiting_list.remove(context->GetObjectName()); + cond.notify_one(); + } + }; + qcloud_cos::MultiGetObjectReq get_req(m_bucket_name, + o.second.m_object_name, + o.second.m_local_file_download); + // 设置完成回调 + get_req.SetDoneCallback(multi_get_done_cb); + // 设置私有数据 + get_req.SetUserData(reinterpret_cast(&concurrent_objects)); + std::cout << "start to download object: " << o.second.m_object_name + << std::endl; + // 开始下载 + m_client->GetObjectAsync(get_req); + } + + // TODO timeout + while (!waiting_list.empty()) { + std::string waiting_objects; + for (auto& o : waiting_list) { + waiting_objects.append(o).append(" "); + } + std::cout << "waiting for " << waiting_objects + << " to complete downloading" << std::endl; + std::unique_lock lock(mutex); + cond.wait(lock); + } + + std::cout << "succeed to download all objects" << std::endl; + + // 校验下载下来的文件 + for (auto& o : concurrent_objects) { + std::string file_md5_download = + TestUtils::CalcFileMd5(o.second.m_local_file_download); + ASSERT_EQ(file_md5_download, o.second.m_file_md5_origin); + } + + for (auto& o : concurrent_objects) { + // 删除对象 + CosResult del_result; + qcloud_cos::DeleteObjectReq del_req(m_bucket_name, + o.second.m_object_name); + qcloud_cos::DeleteObjectResp del_resp; + del_result = m_client->DeleteObject(del_req, &del_resp); + ASSERT_TRUE(del_result.IsSucc()); + // 删除本地文件 + TestUtils::RemoveFile(o.second.m_local_file); + TestUtils::RemoveFile(o.second.m_local_file_download); + } + } +} + +TEST_F(AsyncOpTest, AsyncOpWithException) { + // TODO +} + +} // namespace qcloud_cos diff --git a/unittest/src/bucket_op_test.cpp b/unittest/src/bucket_op_test.cpp index d283621..6547ff4 100644 --- a/unittest/src/bucket_op_test.cpp +++ b/unittest/src/bucket_op_test.cpp @@ -6,9 +6,9 @@ // Description: #include "cos_api.h" -#include "gtest/gtest.h" #include "test_utils.h" #include "util/string_util.h" +#include "gtest/gtest.h" namespace qcloud_cos { @@ -33,30 +33,30 @@ class BucketOpTest : public testing::Test { std::cout << "================SetUpTestCase Begin====================" << std::endl; m_config = new CosConfig("./config.json"); - m_config->SetAccessKey(GetEnv("CPP_SDK_V5_ACCESS_KEY")); - m_config->SetSecretKey(GetEnv("CPP_SDK_V5_SECRET_KEY")); - m_config->SetRegion(GetEnv("CPP_SDK_V5_REGION")); + m_config->SetAccessKey(GetEnvVar("CPP_SDK_V5_ACCESS_KEY")); + m_config->SetSecretKey(GetEnvVar("CPP_SDK_V5_SECRET_KEY")); + m_config->SetRegion(GetEnvVar("CPP_SDK_V5_REGION")); m_client = new CosAPI(*m_config); m_config2 = new CosConfig("./config.json"); - m_config2->SetAccessKey(GetEnv("CPP_SDK_V5_OTHER_ACCESS_KEY")); - m_config2->SetSecretKey(GetEnv("CPP_SDK_V5_OTHER_SECRET_KEY")); - m_config2->SetRegion(GetEnv("CPP_SDK_V5_OTHER_REGION")); + m_config2->SetAccessKey(GetEnvVar("CPP_SDK_V5_OTHER_ACCESS_KEY")); + m_config2->SetSecretKey(GetEnvVar("CPP_SDK_V5_OTHER_SECRET_KEY")); + m_config2->SetRegion(GetEnvVar("CPP_SDK_V5_OTHER_REGION")); m_client2 = new CosAPI(*m_config2); - if (GetEnv("COS_CPP_V5_USE_DNS_CACHE") == "true") { + if (GetEnvVar("COS_CPP_V5_USE_DNS_CACHE") == "true") { std::cout << "================USE DNS CACHE====================" << std::endl; CosSysConfig::SetUseDnsCache(true); } - m_bucket_name = "coscppsdkv5ut" + GetEnv("COS_CPP_V5_TAG") + "-" + - GetEnv("CPP_SDK_V5_APPID"); - m_bucket_name2 = "coscppsdkv5utotherregion" + GetEnv("COS_CPP_V5_TAG") + - "-" + GetEnv("CPP_SDK_V5_APPID"); - m_bucket_name_nil = "coscppsdkv5utt" + GetEnv("COS_CPP_V5_TAG") + "-" + - GetEnv("CPP_SDK_V5_APPID"); - m_bucket_name_wrong = "coscppsdkv5utt" + GetEnv("COS_CPP_V5_TAG") + "-" + - GetEnv("CPP_SDK_V5_APPID") + "1123456"; - m_owner = GetEnv("CPP_SDK_V5_UIN"); - m_owner2 = GetEnv("CPP_SDK_V5_OTHER_UIN"); + m_bucket_name = "coscppsdkv5ut" + GetEnvVar("COS_CPP_V5_TAG") + "-" + + GetEnvVar("CPP_SDK_V5_APPID"); + m_bucket_name2 = "coscppsdkv5utotherregion" + GetEnvVar("COS_CPP_V5_TAG") + + "-" + GetEnvVar("CPP_SDK_V5_APPID"); + m_bucket_name_nil = "coscppsdkv5utt" + GetEnvVar("COS_CPP_V5_TAG") + "-" + + GetEnvVar("CPP_SDK_V5_APPID"); + m_bucket_name_wrong = "coscppsdkv5utt" + GetEnvVar("COS_CPP_V5_TAG") + "-" + + GetEnvVar("CPP_SDK_V5_APPID") + "1123456"; + m_owner = GetEnvVar("CPP_SDK_V5_UIN"); + m_owner2 = GetEnvVar("CPP_SDK_V5_OTHER_UIN"); std::cout << "================SetUpTestCase End====================" << std::endl; } @@ -1289,7 +1289,7 @@ TEST_F(BucketOpTest, InvalidConfig) { HeadBucketResp resp; CosResult result = cos.HeadBucket(req, &resp); ASSERT_TRUE(!result.IsSucc()); - ASSERT_EQ(result.GetErrorInfo(), + ASSERT_EQ(result.GetErrorMsg(), "Invalid access_key secret_key or region, please check your " "configuration"); } diff --git a/unittest/src/live_channel_test.cpp b/unittest/src/live_channel_test.cpp index cc9dd77..e7f16d6 100644 --- a/unittest/src/live_channel_test.cpp +++ b/unittest/src/live_channel_test.cpp @@ -1,8 +1,8 @@ #include #include "cos_api.h" -#include "gtest/gtest.h" #include "test_utils.h" +#include "gtest/gtest.h" namespace qcloud_cos { @@ -12,12 +12,12 @@ class LiveChannelOpTest : public testing::Test { std::cout << "================SetUpTestCase Begin====================" << std::endl; m_config = new CosConfig("./config.json"); - m_config->SetAccessKey(GetEnv("CPP_SDK_V5_ACCESS_KEY")); - m_config->SetSecretKey(GetEnv("CPP_SDK_V5_SECRET_KEY")); + m_config->SetAccessKey(GetEnvVar("CPP_SDK_V5_ACCESS_KEY")); + m_config->SetSecretKey(GetEnvVar("CPP_SDK_V5_SECRET_KEY")); m_client = new CosAPI(*m_config); - m_bucket_name = "jackytestgz1" + GetEnv("COS_CPP_V5_TAG") + "-" + - GetEnv("CPP_SDK_V5_APPID"); + m_bucket_name = "jackytestgz1" + GetEnvVar("COS_CPP_V5_TAG") + "-" + + GetEnvVar("CPP_SDK_V5_APPID"); { PutBucketReq req(m_bucket_name); PutBucketResp resp; diff --git a/unittest/src/object_op_test.cpp b/unittest/src/object_op_test.cpp index cd90a04..f4611b6 100644 --- a/unittest/src/object_op_test.cpp +++ b/unittest/src/object_op_test.cpp @@ -10,10 +10,10 @@ #include "Poco/MD5Engine.h" #include "Poco/StreamCopier.h" #include "cos_api.h" -#include "gtest/gtest.h" #include "test_utils.h" #include "util/file_util.h" #include "util/simple_dns_cache.h" +#include "gtest/gtest.h" /* export CPP_SDK_V5_ACCESS_KEY=xxx @@ -38,20 +38,20 @@ class ObjectOpTest : public testing::Test { std::cout << "================SetUpTestCase Begin====================" << std::endl; m_config = new CosConfig("./config.json"); - m_config->SetAccessKey(GetEnv("CPP_SDK_V5_ACCESS_KEY")); - m_config->SetSecretKey(GetEnv("CPP_SDK_V5_SECRET_KEY")); - m_config->SetRegion(GetEnv("CPP_SDK_V5_REGION")); - if (GetEnv("COS_CPP_V5_USE_DNS_CACHE") == "true") { + m_config->SetAccessKey(GetEnvVar("CPP_SDK_V5_ACCESS_KEY")); + m_config->SetSecretKey(GetEnvVar("CPP_SDK_V5_SECRET_KEY")); + m_config->SetRegion(GetEnvVar("CPP_SDK_V5_REGION")); + if (GetEnvVar("COS_CPP_V5_USE_DNS_CACHE") == "true") { std::cout << "================USE DNS CACHE====================" << std::endl; CosSysConfig::SetUseDnsCache(true); } m_client = new CosAPI(*m_config); - m_bucket_name = "coscppsdkv5ut" + GetEnv("COS_CPP_V5_TAG") + "-" + - GetEnv("CPP_SDK_V5_APPID"); - m_bucket_name2 = "coscppsdkv5utcopy" + GetEnv("COS_CPP_V5_TAG") + "-" + - GetEnv("CPP_SDK_V5_APPID"); + m_bucket_name = "coscppsdkv5ut" + GetEnvVar("COS_CPP_V5_TAG") + "-" + + GetEnvVar("CPP_SDK_V5_APPID"); + m_bucket_name2 = "coscppsdkv5utcopy" + GetEnvVar("COS_CPP_V5_TAG") + "-" + + GetEnvVar("CPP_SDK_V5_APPID"); { PutBucketReq req(m_bucket_name); PutBucketResp resp; @@ -429,7 +429,7 @@ TEST_F(ObjectOpTest, DeleteObjectTest) { DeleteObjectReq req(m_bucket_name, object_name); DeleteObjectResp resp; CosResult result = m_client->DeleteObject(req, &resp); - std::string errinfo = result.GetErrorInfo(); + std::string errinfo = result.GetErrorMsg(); EXPECT_EQ("Delete object's name is empty.", errinfo); } } @@ -489,7 +489,7 @@ TEST_F(ObjectOpTest, GetObjectByFileTest) { } } -TEST_F(ObjectOpTest, MultiUploadObjectTest) { +TEST_F(ObjectOpTest, MultiPutObjectTest) { { uint64_t part_size = 20 * 1000 * 1000; uint64_t max_part_num = 3; @@ -608,7 +608,7 @@ TEST_F(ObjectOpTest, MultiUploadObjectTest) { } } -TEST_F(ObjectOpTest, MultiUploadObjectTest_OneStep) { +TEST_F(ObjectOpTest, MultiPutObjectTest_OneStep) { { std::string filename = "multi_upload_object_one_step"; std::string object_name = filename; @@ -624,11 +624,11 @@ TEST_F(ObjectOpTest, MultiUploadObjectTest_OneStep) { } // 2. 上传 - MultiUploadObjectReq req(m_bucket_name, object_name, filename); + MultiPutObjectReq req(m_bucket_name, object_name, filename); req.SetRecvTimeoutInms(1000 * 200); - MultiUploadObjectResp resp; + MultiPutObjectResp resp; - CosResult result = m_client->MultiUploadObject(req, &resp); + CosResult result = m_client->PutObject(req, &resp); EXPECT_TRUE(result.IsSucc()); // 3. 删除临时文件 @@ -652,11 +652,11 @@ TEST_F(ObjectOpTest, MultiUploadObjectTest_OneStep) { } // 2. 上传 - MultiUploadObjectReq req(m_bucket_name, object_name, filename); + MultiPutObjectReq req(m_bucket_name, object_name, filename); req.SetXCosServerSideEncryption("AES256"); - MultiUploadObjectResp resp; + MultiPutObjectResp resp; - CosResult result = m_client->MultiUploadObject(req, &resp); + CosResult result = m_client->PutObject(req, &resp); ASSERT_TRUE(result.IsSucc()); EXPECT_EQ("AES256", resp.GetXCosServerSideEncryption()); @@ -714,8 +714,8 @@ TEST_F(ObjectOpTest, ObjectACLTest) { PutObjectACLReq put_acl_req(m_bucket_name, object_name); PutObjectACLResp put_acl_resp; - std::string uin(GetEnv("CPP_SDK_V5_UIN")); - std::string grant_uin(GetEnv("CPP_SDK_V5_OTHER_UIN")); + std::string uin(GetEnvVar("CPP_SDK_V5_UIN")); + std::string grant_uin(GetEnvVar("CPP_SDK_V5_OTHER_UIN")); qcloud_cos::Owner owner = {"qcs::cam::uin/" + uin + ":uin/" + uin, "qcs::cam::uin/" + uin + ":uin/" + uin}; @@ -1039,109 +1039,6 @@ TEST_F(ObjectOpTest, SelectObjectContent) { } } -TEST_F(ObjectOpTest, AsyncUploadDownload) { - // std::vector base_size_v = {1024}; - std::vector base_size_v = {5, 35, 356, 1024, - 2545, 25678, 1024 * 1024, 5 * 1024 * 1024}; - for (auto& size : base_size_v) { - for (int i = 1; i < 10; i++) { - std::cout << "base_size: " << size << ", test_time: " << i << std::endl; - - size_t file_size = ((rand() % 100) + 1) * size; - std::string object_name = "test_async_" + std::to_string(file_size); - std::string local_file = "./" + object_name; - - std::cout << "generate file: " << local_file << std::endl; - TestUtils::WriteRandomDatatoFile(local_file, file_size); - - qcloud_cos::MultiUploadObjectReq put_req(m_bucket_name, object_name, - local_file); - qcloud_cos::MultiUploadObjectResp put_resp; - put_req.SetRecvTimeoutInms(1000 * 200); - - auto process_cb = [](uint64_t transferred_size, uint64_t total_size, - void* user_data) { - qcloud_cos::ObjectReq* req = - static_cast(user_data); - int curr_pct = (int)(100 * transferred_size / total_size); - static int last_pct = 0; - if (curr_pct != last_pct) { - std::cout << "ProcessCallback,ObjectName:" << req->GetObjectName() - << ",TranferedSize:" << transferred_size - << ",TotalSize:" << total_size << ",Pct:%" << curr_pct - << std::endl; - last_pct = curr_pct; - } - }; - - auto status_cb = [](const std::string& status, void* user_data) { - qcloud_cos::ObjectReq* req = - static_cast(user_data); - std::cout << "StatusCallback,ObjectName:" << req->GetObjectName() - << ",CurrentStatus:" << status << std::endl; - }; - - std::cout << "async upload object: " << object_name - << ", size: " << file_size << std::endl; - // 设置上传进度回调 - put_req.SetTransferProgressCallback(process_cb); - // 设置上传状态回调 - put_req.SetTransferStatusCallback(status_cb); - // 设置私有数据 - put_req.SetTransferCallbackUserData(&put_req); - - // 开始上传 - SharedTransferHandler handler = - m_client->PutObjectAsync(put_req, &put_resp); - - // 等待上传结束 - handler->WaitUntilFinish(); - - ASSERT_TRUE(handler->m_result.IsSucc()); - EXPECT_EQ(handler->GetStatus(), TransferStatus::COMPLETED); - - std::string local_file_download = local_file + "_download"; - - qcloud_cos::MultiGetObjectReq get_req(m_bucket_name, object_name, - local_file_download); - qcloud_cos::MultiGetObjectResp get_resp; - // 设置进度回调 - get_req.SetTransferProgressCallback(process_cb); - // 设置状态回调 - get_req.SetTransferStatusCallback(status_cb); - // 设置私有数据 - get_req.SetTransferCallbackUserData(&get_req); - std::cout << "async download object: " << object_name << std::endl; - - // 开始下载 - handler = m_client->GetObjectAsync(get_req, &get_resp); - - // 等待下载结束 - handler->WaitUntilFinish(); - ASSERT_TRUE(handler->m_result.IsSucc()); - ASSERT_EQ(file_size, get_resp.GetContentLength()); - EXPECT_EQ(handler->GetStatus(), TransferStatus::COMPLETED); - - // 校验文件 - std::string file_md5_origin = TestUtils::CalcFileMd5(local_file); - std::string file_md5_download = - TestUtils::CalcFileMd5(local_file_download); - ASSERT_EQ(file_md5_download, file_md5_origin); - - // 删除对象 - CosResult del_result; - qcloud_cos::DeleteObjectReq del_req(m_bucket_name, object_name); - qcloud_cos::DeleteObjectResp del_resp; - del_result = m_client->DeleteObject(del_req, &del_resp); - ASSERT_TRUE(del_result.IsSucc()); - - // 删除本地文件 - TestUtils::RemoveFile(local_file); - TestUtils::RemoveFile(local_file_download); - } - } -} - TEST_F(ObjectOpTest, TestPutObjectWithMeta) { std::vector base_size_v = {1024}; for (auto& size : base_size_v) { @@ -1271,7 +1168,7 @@ TEST_F(ObjectOpTest, TestPutObjectWithMeta) { } } -TEST_F(ObjectOpTest, TestMultiUploadObjectWithMeta) { +TEST_F(ObjectOpTest, TestMultiPutObjectWithMeta) { std::vector base_size_v = {1024 * 1024}; for (auto& size : base_size_v) { for (int i = 0; i < 5; i++) { @@ -1285,8 +1182,8 @@ TEST_F(ObjectOpTest, TestMultiUploadObjectWithMeta) { TestUtils::WriteRandomDatatoFile(local_file, file_size); // put object - qcloud_cos::MultiUploadObjectReq put_req(m_bucket_name, object_name, - local_file); + qcloud_cos::MultiPutObjectReq put_req(m_bucket_name, object_name, + local_file); put_req.SetXCosStorageClass(kStorageClassStandardIA); put_req.SetCacheControl("max-age=86400"); put_req.SetXCosMeta("key1", "val1"); @@ -1296,10 +1193,10 @@ TEST_F(ObjectOpTest, TestMultiUploadObjectWithMeta) { put_req.SetContentEncoding("gzip"); put_req.SetContentDisposition("attachment; filename=example"); put_req.SetContentType("image/jpeg"); - qcloud_cos::MultiUploadObjectResp put_resp; + qcloud_cos::MultiPutObjectResp put_resp; std::cout << "upload object: " << object_name << ", size: " << file_size << std::endl; - CosResult put_result = m_client->MultiUploadObject(put_req, &put_resp); + CosResult put_result = m_client->PutObject(put_req, &put_resp); ASSERT_TRUE(put_result.IsSucc()); ASSERT_TRUE(!put_resp.GetXCosRequestId().empty()); ASSERT_EQ(put_resp.GetContentLength(), 0); @@ -1377,7 +1274,7 @@ TEST_F(ObjectOpTest, TestMultiUploadObjectWithMeta) { ASSERT_EQ(get_resp.GetXCosMeta("key2"), "val2"); ASSERT_EQ(get_resp.GetXCosStorageClass(), kStorageClassStandardIA); ASSERT_EQ(get_resp.GetExpires(), "1000"); - ASSERT_EQ(get_resp.GetContentLength(), file_size); + //ASSERT_EQ(get_resp.GetContentLength(), file_size); ASSERT_EQ(get_resp.GetContentEncoding(), "gzip"); ASSERT_EQ(get_resp.GetContentDisposition(), "attachment; filename=example"); @@ -1548,14 +1445,13 @@ TEST_F(ObjectOpTest, MultiUploadVaryName) { std::cout << "generate file: " << local_file << std::endl; TestUtils::WriteRandomDatatoFile(local_file, test_file_size); uint64_t file_crc64_origin = FileUtil::GetFileCrc64(local_file); - MultiUploadObjectReq multiupload_req(m_bucket_name, object_name, - local_file); - MultiUploadObjectResp multiupload_resp; + MultiPutObjectReq multiupload_req(m_bucket_name, object_name, local_file); + MultiPutObjectResp multiupload_resp; ASSERT_TRUE(multiupload_req.CheckCRC64()); // upload object CosResult multiupload_result = - m_client->MultiUploadObject(multiupload_req, &multiupload_resp); + m_client->PutObject(multiupload_req, &multiupload_resp); ASSERT_TRUE(multiupload_result.IsSucc()); ASSERT_TRUE(!multiupload_resp.GetXCosRequestId().empty()); ASSERT_TRUE(multiupload_resp.GetContentLength() == 0); @@ -1598,13 +1494,12 @@ TEST_F(ObjectOpTest, MultiUploadVaryName) { // upload not exist file std::string object_name = "not_exist_file"; std::string local_file_not_exist = "./not_exist_file"; - MultiUploadObjectReq multiupload_req(m_bucket_name, object_name, - local_file_not_exist); - MultiUploadObjectResp multiupload_resp; - CosResult result = - m_client->MultiUploadObject(multiupload_req, &multiupload_resp); + MultiPutObjectReq multiupload_req(m_bucket_name, object_name, + local_file_not_exist); + MultiPutObjectResp multiupload_resp; + CosResult result = m_client->PutObject(multiupload_req, &multiupload_resp); ASSERT_TRUE(!result.IsSucc()); - ASSERT_TRUE(result.GetErrorInfo().find("failed to open file") != + ASSERT_TRUE(result.GetErrorMsg().find("failed to open file") != std::string::npos); } } @@ -1625,14 +1520,13 @@ TEST_F(ObjectOpTest, MultiUploadVaryPartSizeAndThreadPoolSize) { std::cout << "generate file: " << local_file << std::endl; TestUtils::WriteRandomDatatoFile(local_file, test_file_size); uint64_t file_crc64_origin = FileUtil::GetFileCrc64(local_file); - MultiUploadObjectReq multiupload_req(m_bucket_name, object_name, - local_file); - MultiUploadObjectResp multiupload_resp; + MultiPutObjectReq multiupload_req(m_bucket_name, object_name, local_file); + MultiPutObjectResp multiupload_resp; ASSERT_TRUE(multiupload_req.CheckCRC64()); // upload object CosResult multiupload_result = - m_client->MultiUploadObject(multiupload_req, &multiupload_resp); + m_client->PutObject(multiupload_req, &multiupload_resp); ASSERT_TRUE(multiupload_result.IsSucc()); ASSERT_TRUE(!multiupload_resp.GetXCosRequestId().empty()); ASSERT_TRUE(multiupload_resp.GetContentLength() == 0); @@ -1705,7 +1599,7 @@ TEST_F(ObjectOpTest, InvalidConfig) { PutObjectByStreamResp resp; CosResult result = cos.PutObject(req, &resp); ASSERT_TRUE(!result.IsSucc()); - ASSERT_EQ(result.GetErrorInfo(), + ASSERT_EQ(result.GetErrorMsg(), "Invalid access_key secret_key or region, please check your " "configuration"); } @@ -1718,7 +1612,7 @@ TEST_F(ObjectOpTest, InvalidConfig) { PutObjectByStreamResp resp; CosResult result = cos.PutObject(req, &resp); ASSERT_TRUE(!result.IsSucc()); - ASSERT_EQ(result.GetErrorInfo(), + ASSERT_EQ(result.GetErrorMsg(), "Invalid access_key secret_key or region, please check your " "configuration"); } diff --git a/unittest/src/test_utils.cpp b/unittest/src/test_utils.cpp index a2eb081..41744a6 100644 --- a/unittest/src/test_utils.cpp +++ b/unittest/src/test_utils.cpp @@ -69,7 +69,7 @@ std::string TestUtils::CalcStreamSHA1(std::istream& is) { return Poco::DigestEngine::digestToHex(sha1.digest()); } -std::string TestUtils::GetEnv(const std::string& env_var_name) { +std::string TestUtils::GetEnvVar(const std::string& env_var_name) { char const* tmp = getenv(env_var_name.c_str()); if (tmp == NULL) { return "NOT_EXIST_ENV_" + env_var_name; diff --git a/unittest/src/test_utils.h b/unittest/src/test_utils.h index 9871f83..71b6d8a 100644 --- a/unittest/src/test_utils.h +++ b/unittest/src/test_utils.h @@ -15,7 +15,17 @@ class TestUtils { static std::string CalcStreamMd5(std::istream& is); static std::string CalcStringMd5(const std::string& str); static std::string CalcStreamSHA1(std::istream& is); - static std::string GetEnv(const std::string& env_var_name); + static std::string GetEnvVar(const std::string& env_var_name); }; -#define GetEnv TestUtils::GetEnv +#define GetEnvVar TestUtils::GetEnvVar + +struct FileInfo { + std::string m_object_name; + std::string m_local_file; + std::string m_local_file_download; + uint64_t m_file_size; + uint64_t m_file_crc64_origin; + std::string m_file_md5_origin; +}; + } // namespace qcloud_cos