Guest User

Untitled

a guest
Mar 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # flake8: noqa
  3.  
  4. from qiniu import Auth, put_file, etag, urlsafe_base64_encode
  5. import qiniu.config
  6. from qiniu.compat import is_py2, is_py3
  7. import sys
  8.  
  9. # 需要填写你的 Access Key 和 Secret Key
  10. access_key = '...'
  11. secret_key = '...'
  12.  
  13. # 构建鉴权对象
  14. q = Auth(access_key, secret_key)
  15.  
  16. # 要上传的空间
  17. bucket_name = '...'
  18.  
  19. # 上传到七牛后保存的文件名
  20. key = sys.argv[1]
  21.  
  22. # 生成上传 Token,可以指定过期时间等
  23. token = q.upload_token(bucket_name, key, 3600)
  24.  
  25. # 要上传文件的本地路径
  26. localfile = sys.argv[2]
  27.  
  28. ret, info = put_file(token, key, localfile)
  29. #print(ret)
  30. print(info)
  31.  
  32. if is_py2:
  33. assert ret['key'].encode('utf-8') == key
  34. elif is_py3:
  35. assert ret['key'] == key
  36.  
  37. assert ret['hash'] == etag(localfile)
Add Comment
Please, Sign In to add comment