Files
fcb_photo_review/photo_review/util/ucloud.py
2024-06-06 10:39:34 +08:00

28 lines
949 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# https://github.com/ucloud/ufile-sdk-python
import logging
from ufile import filemanager
public_key = "4Z7QYI7qml36QRjcCjKrls7aHl1R6H6uq"
private_key = "FIdW1Kev1Ge3K7GHXzSLyGG1wTnaG6LE9BxmIVubcCaG"
bucket = "drg100"
upload_suffix = ".cn-sh2.ufileos.com"
download_suffix = ".cn-sh2.ufileos.com"
def get_private_url(key):
get_ufile_handler = filemanager.FileManager(public_key, private_key, upload_suffix, download_suffix)
# 判断文件是否存在
_, resp = get_ufile_handler.head_file(bucket, key)
if resp.status_code != 200:
logging.warning("uCloud中未找到(%s)! status: %d error: %s", key, resp.status_code, resp.error)
return None
# 获取公有空间下载url
# url = get_ufile_handler.public_download_url(bucket, key)
# 获取私有空间下载url, expires为下载链接有效期单位为秒
url = get_ufile_handler.private_download_url(bucket, key, expires=3600)
return url