From 44edcfdf6e34bd1dc8b3e41e1ec7202203cc8d20 Mon Sep 17 00:00:00 2001 From: wqingzhang Date: Wed, 20 Apr 2022 11:17:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=97=B6=E5=A4=84=E7=90=86=E5=85=BC=E5=AE=B9=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E5=8E=9F=E5=9B=BE=EF=BC=8C=E4=B8=8D=E6=A3=80=E6=9F=A5Etag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/request/data_process_req.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/request/data_process_req.h b/include/request/data_process_req.h index d4d9eca..603fc50 100644 --- a/include/request/data_process_req.h +++ b/include/request/data_process_req.h @@ -601,7 +601,12 @@ class PutImageByFileReq : public PutObjectByFileReq { PutImageByFileReq(const std::string& bucket_name, const std::string& object_name, const std::string& local_image) - : PutObjectByFileReq(bucket_name, object_name, local_image) {} + : PutObjectByFileReq(bucket_name, object_name, local_image) { + // 图片上传时处理可能会覆盖原图,本地文件etag与上传到COS的etag文件的etag可能不一致 + // 这种情况是合理的,所以这里不需要检查etag + TurnOffComputeConentMd5(); + TurnOffCheckETag(); + } virtual ~PutImageByFileReq() {} From 1b6a7d7c4d576be9dde45d54d9daab2211df2948 Mon Sep 17 00:00:00 2001 From: wqingzhang9836 Date: Wed, 20 Apr 2022 18:40:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=97=B6=E5=A4=84=E7=90=86=E8=8B=A5=E8=A6=86=E7=9B=96=E5=8E=9F?= =?UTF-8?q?=E5=9B=BE=E5=88=99=E4=B8=8D=E6=A3=80=E6=9F=A5Etag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/cos_api.h | 2 +- include/request/data_process_req.h | 14 ++++++++------ src/cos_api.cpp | 3 ++- src/request/data_process_req.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/include/cos_api.h b/include/cos_api.h index 08e167a..abc58c5 100644 --- a/include/cos_api.h +++ b/include/cos_api.h @@ -773,7 +773,7 @@ class CosAPI { /** 图片持久化处理 **/ /*** 上传时处理 ***/ - CosResult PutImage(const PutImageByFileReq& req, PutImageByFileResp* resp); + CosResult PutImage(PutImageByFileReq& req, PutImageByFileResp* resp); /*** 云上数据处理 ***/ CosResult CloudImageProcess(const CloudImageProcessReq& req, diff --git a/include/request/data_process_req.h b/include/request/data_process_req.h index 603fc50..fc89eed 100644 --- a/include/request/data_process_req.h +++ b/include/request/data_process_req.h @@ -277,6 +277,8 @@ class PicOperation { PicOperation() : is_pic_info(true) {} virtual ~PicOperation() {} + std::vector GetRules() const { return rules; } + void AddRule(const PicRules& rule) { rules.push_back(rule); } void TurnOffPicInfo() { is_pic_info = false; } @@ -601,20 +603,20 @@ class PutImageByFileReq : public PutObjectByFileReq { PutImageByFileReq(const std::string& bucket_name, const std::string& object_name, const std::string& local_image) - : PutObjectByFileReq(bucket_name, object_name, local_image) { - // 图片上传时处理可能会覆盖原图,本地文件etag与上传到COS的etag文件的etag可能不一致 - // 这种情况是合理的,所以这里不需要检查etag - TurnOffComputeConentMd5(); - TurnOffCheckETag(); - } + : PutObjectByFileReq(bucket_name, object_name, local_image) {} virtual ~PutImageByFileReq() {} + PicOperation GetPictureOperation() const { return m_pic_operation; } + void SetPicOperation(const PicOperation& pic_operation) { m_pic_operation = pic_operation; AddHeader("Pic-Operations", m_pic_operation.GenerateJsonString()); } + // 检查图片处理的效果图文件是否覆盖了原图 + void CheckCoverOriginImage(); + private: PicOperation m_pic_operation; }; diff --git a/src/cos_api.cpp b/src/cos_api.cpp index 134bcf1..0bd4851 100644 --- a/src/cos_api.cpp +++ b/src/cos_api.cpp @@ -582,8 +582,9 @@ CosResult CosAPI::MoveObject(const MoveObjectReq& req) { return m_object_op.MoveObject(req); } -CosResult CosAPI::PutImage(const PutImageByFileReq& req, +CosResult CosAPI::PutImage(PutImageByFileReq& req, PutImageByFileResp* resp) { + req.CheckCoverOriginImage(); return m_object_op.PutImage(req, resp); } diff --git a/src/request/data_process_req.cpp b/src/request/data_process_req.cpp index a19889b..c37b679 100644 --- a/src/request/data_process_req.cpp +++ b/src/request/data_process_req.cpp @@ -7,6 +7,31 @@ namespace qcloud_cos { +void PutImageByFileReq:: CheckCoverOriginImage() { + std::vector pic_rules = m_pic_operation.GetRules(); + std::string object_name = GetObjectName(); + std::string object_dir = object_name.substr(0, object_name.find_last_of("/") + 1); + for (std::vector::const_iterator c_itr = pic_rules.begin(); + c_itr != pic_rules.end(); ++c_itr) { + const PicRules& pic_rule = *c_itr; + std::string pic_absolute_key; + if (StringUtil::StringStartsWith(pic_rule.fileid, "/")) { + // fileid 以“/”开头为绝对路径 + pic_absolute_key = StringUtil::StringRemovePrefix(pic_rule.fileid, "/"); + } else { + // fileid 不以“/”开头为相对路径 + pic_absolute_key = object_dir + pic_rule.fileid; + } + // 如果图片处理的效果图存放路径与上传文件路径相同,则会覆盖上传的原文件 + // 覆盖上传原文件后Etag与本地文件不相同,此时不比较Etag + if (pic_absolute_key == object_name) { + TurnOffCheckETag(); + TurnOffComputeConentMd5(); + break; + } + } +} + bool CreateDocProcessJobsReq::GenerateRequestBody(std::string* body) const { rapidxml::xml_document<> doc; rapidxml::xml_node<>* root_node = doc.allocate_node(