12345678910111213141516171819202122232425262728293031 |
- from qiniu import Auth, put_file, etag,put_data
- import qiniu.config
- from django.conf import settings
- def upload(file_data):
- # 需要填写你的 Access Key 和 Secret Key
- access_key = settings.QINIU_ACCESS_KEY
- secret_key = settings.QINIU_SECRET_KEY
- # 构建鉴权对象
- q = Auth(access_key, secret_key)
- # 要上传的空间
- bucket_name = settings.BUCKET_NAME
- # 上传后保存的文件名
- # key = 'my-python-logo.png'
- key = None
- # 生成上传 Token,可以指定过期时间等
- token = q.upload_token(bucket_name, key, 3600)
- # 要上传文件的本地路径
- # localfile = './sync/bbb.jpg'
- # ret, info = put_file(token, key, localfile)
- # print(info)
- # assert ret['key'] == key
- # assert ret['hash'] == etag(localfile)
- ret, info = put_data(token,key,file_data)
- return ret.get("key")
- # with open('D:\\213.png',"rb") as f:
- # putile=f.read()
- # info = upload(putile)
- # print(putile)
|