Skip to content

Commit

Permalink
fix(hist): fix history md encoding problem
Browse files Browse the repository at this point in the history
  • Loading branch information
MorvanZhou committed Apr 23, 2024
1 parent 7449a02 commit f508e19
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/retk/core/node/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ def __get_md_from_cos(uid: str, nid: str, version: str) -> Tuple[str, const.Code
Bucket=settings.COS_BUCKET_NAME,
Key=key,
)
md = res["Body"].read().decode("utf-8")
md_body = res["Body"].read()
except CosServiceError as e:
logger.error(f"failed to get file from cos: {e}")
return "", const.Code.COS_ERROR
try:
md = md_body.decode("utf-8")
except UnicodeDecodeError as e:
logger.error(f"failed to decode md: {e}. md: {md_body}")
return "", const.Code.OPERATION_FAILED
return md, const.Code.OK


Expand All @@ -133,7 +138,7 @@ def __save_md_to_cos(uid: str, nid: str, version: str, md: str) -> const.Code:
try:
_ = cos_client.put_object(
Bucket=settings.COS_BUCKET_NAME,
Body=md,
Body=md.encode("utf-8"),
Key=key,
StorageClass='STANDARD', # 'STANDARD'|'STANDARD_IA'|'ARCHIVE',
EnableMD5=False,
Expand Down

0 comments on commit f508e19

Please sign in to comment.