Created
November 26, 2017 12:55
自动上传覆盖某个固定的文件到七牛
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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