Skip to content

Instantly share code, notes, and snippets.

@chchuj
Created November 26, 2017 12:55
Show Gist options
  • Save chchuj/f20f7e52cfd713b3d109e6487bdb6e4d to your computer and use it in GitHub Desktop.
Save chchuj/f20f7e52cfd713b3d109e6487bdb6e4d to your computer and use it in GitHub Desktop.
自动上传覆盖某个固定的文件到七牛
# -*- coding: utf-8 -*-
import os
import sys
from qiniu import Auth, put_file, etag, urlsafe_base64_encode
import qiniu.config
access_key = ' ' # 个人中心->密匙管理->AK
secret_key = ' ' # 个人中心->密匙管理->SK
bucket_name = '' # 七牛空间名
#构建鉴权对象
q = Auth(access_key, secret_key)
#上传到七牛后保存的文件名
key = 'atom.xml'
#生成上传 Token,可以指定过期时间等
token = q.upload_token(bucket_name, key, )
#要上传文件的本地路径
localfile = 'E:\\Computer\\Blog\\blog\\public\\atom.xml'
ret, info = put_file(token, key, localfile)
print(info)
if ret and ret['key'] == key:
print('%s done' % localfile)
else:
print('%s error' % localfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment