Created
August 23, 2015 03:54
-
-
Save lzjun567/6be73383ce84e7e8ee40 to your computer and use it in GitHub Desktop.
上传本地文件到七牛指定的存储空间
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__author__ = 'liuzhijun' | |
import click | |
import qiniu | |
access_key = "xxxx" | |
secret_key = "xxxx" | |
q = qiniu.Auth(access_key, secret_key) | |
@click.command() | |
@click.option('--bucket_name', default="blog-resource", | |
help='you can choice [blog-resource, github-note, foofish, gongshare]') | |
@click.option('--file_path', prompt='file path', | |
help='the local file path you will be upload') | |
@click.option('--saved_name', prompt='saved name', help="the file name showed in qiniu") | |
def upload(bucket_name, file_path, saved_name): | |
""" | |
上传文件到七牛服务器 | |
:param bucket_name: 指定存储空间 | |
:param file_path: 本地文件路径 | |
:param saved_name: 显示在七牛的文件名称 | |
:return: | |
""" | |
token = q.upload_token(bucket_name, saved_name) | |
ret, info = qiniu.put_file(token, saved_name, file_path, check_crc=True) | |
print ret, info | |
if __name__ == '__main__': | |
upload() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment