如何通过python上传文件到七牛
1个回答
展开全部
首先要安装一个qiniu的包,下面是示例代码
from qiniu import Auth, put_data, put_file
accessKey = "xxx"
secretKey = "xxx"
def upload_data(data, bucket_name):
#生成上传凭证
q = Auth(accessKey, secretKey)
key = str(int(time() * 1000))
token = q.upload_token(bucket_name, key)
#上传文件
retData, respInfo = put_data(token, key, data)
return 'xxx.clouddn.com/' + key
with open('meelo.jpg', 'rb') as f:
url = upload_data(f.read(), 'xxxx')
会返回上传文件的url
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询