qiniu.py 574 B

1234567891011121314151617181920
  1. # encoding: utf-8
  2. from cn.localhost01.__init__ import qiniu_ak, qiniu_sk, qiniu_bucket, qiniu_domain
  3. from qiniu import Auth, put_file
  4. import os
  5. # 构建鉴权对象
  6. auth = Auth(qiniu_ak, qiniu_sk)
  7. def upload_file(local_path):
  8. # 0.获取文件名
  9. new_file_name = os.path.basename(local_path)
  10. # 1.获取上传token
  11. token = auth.upload_token(qiniu_bucket, new_file_name)
  12. # 2.上传
  13. ret, info = put_file(token, new_file_name, local_path)
  14. if info.status_code == 200:
  15. return qiniu_domain + "/" + new_file_name + "?attname="
  16. return None