照片涂抹保存到云端

This commit is contained in:
2024-07-09 21:02:04 +08:00
parent a7d1c479a8
commit 457ed3ed07
2 changed files with 32 additions and 1 deletions

View File

@@ -224,6 +224,9 @@ def photo_mask(pk_phhd, content):
.all()
session.close()
for phrec in phrecs:
is_copy_success = ucloud.copy_file("drg100", phrec.cfjaddress, "drg103", phrec.cfjaddress)
if not is_copy_success:
continue
img_url = ucloud.get_private_url(phrec.cfjaddress)
if not img_url:
continue
@@ -247,7 +250,12 @@ def photo_mask(pk_phhd, content):
)
cv2.rectangle(image, (int(result[0]), int(result[1])), (int(result[2]), int(result[3])),
(255, 255, 255), -1, 0)
cv2.imwrite(f"./mask_test/{phrec.cfjaddress}.jpg", image)
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
cv2.imwrite(temp_file.name, image)
for i in range(3):
is_upload_success = ucloud.upload_file(phrec.cfjaddress, temp_file.name)
if is_upload_success:
break
if __name__ == '__main__':

View File

@@ -21,3 +21,26 @@ def get_private_url(key):
# 获取私有空间下载url, expires为下载链接有效期单位为秒
url = get_ufile_handler.private_download_url(BUCKET, key, expires=3600)
return url
def copy_file(source_bucket, source_key, target_bucket, target_key):
copy_ufile_handler = filemanager.FileManager(PUBLIC_KEY, PRIVATE_KEY, UPLOAD_SUFFIX, DOWNLOAD_SUFFIX)
# 拷贝文件
ret, resp = copy_ufile_handler.copy(target_bucket, target_key, source_bucket, source_key)
if resp.status_code != 200:
logging.warning(
f"将({source_key})从({source_bucket})拷贝到({target_bucket})失败! status: {resp.status_code} error: {resp.error}")
return False
return True
def upload_file(key, file_path):
putufile_handler = filemanager.FileManager(PUBLIC_KEY, PRIVATE_KEY, UPLOAD_SUFFIX, DOWNLOAD_SUFFIX)
# 普通上传文件至空间
ret, resp = putufile_handler.putfile(BUCKET, key, file_path, header=None)
if resp.status_code != 200:
logging.warning(f"上传({key})失败! status: {resp.status_code} error: {resp.error}")
return False
return True