独立ucloud方法,添加ucloud配置类

This commit is contained in:
2024-06-13 09:12:11 +08:00
parent 1f128c0cb4
commit 20dee59784
5 changed files with 27 additions and 16 deletions

0
ucloud/__init__.py Normal file
View File

23
ucloud/ucloud.py Normal file
View File

@@ -0,0 +1,23 @@
# https://github.com/ucloud/ufile-sdk-python
import logging
from ufile import filemanager
from config.ucloud import PUBLIC_KEY, PRIVATE_KEY, UPLOAD_SUFFIX, DOWNLOAD_SUFFIX, BUCKET
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