首先是下载依赖
我这里是windows
:
pip install oss2
代码也是一如既往的简单,毕竟是python
嘛
from io import BytesIO
import oss2
ACCESS_KEY_ID = ''
ACCESS_KEY_SECRET = ''
ENDPOINT = 'oss-cn-chengdu.aliyuncs.com'
BUCKET_NAME = 'waibi'
AUTH = oss2.Auth(ACCESS_KEY_ID, ACCESS_KEY_SECRET)
BUCKET = oss2.Bucket(AUTH, ENDPOINT, BUCKET_NAME)
def download_file_bytes(file_name):
return BUCKET.get_object(file_name)
def upload_file(file_object, path):
BUCKET.put_object(path, file_object)