You've already forked FrameTour-RenderWorker
对接
This commit is contained in:
23
util/oss.py
23
util/oss.py
@ -1,7 +1,9 @@
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def upload_to_oss_use_signed_url(url, file_path):
|
||||
def upload_to_oss(url, file_path):
|
||||
"""
|
||||
使用签名URL上传文件到OSS
|
||||
:param str url: 签名URL
|
||||
@ -15,3 +17,22 @@ def upload_to_oss_use_signed_url(url, file_path):
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return False
|
||||
|
||||
def download_from_oss(url, file_path):
|
||||
"""
|
||||
使用签名URL下载文件到OSS
|
||||
:param str url: 签名URL
|
||||
:param Union[LiteralString, str, bytes] file_path: 文件路径
|
||||
:return bool: 是否成功
|
||||
"""
|
||||
file_dir, file_name = os.path.split(file_path)
|
||||
if not os.path.exists(file_dir):
|
||||
os.makedirs(file_dir)
|
||||
try:
|
||||
response = requests.get(url)
|
||||
with open(file_path, 'wb') as f:
|
||||
f.write(response.content)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return False
|
||||
|
Reference in New Issue
Block a user