#SDK自己装去吧,pip3 install qiniu

from qiniu import Auth, put_file, etag, BucketManager
import qiniu.config

#需要填写你的 Access Key 和 Secret Key
access_key = 'slkdfjaasdfjhklajsfwoijafjfr3kfnn3f3k334'
secret_key = 'thfnwuhwui3ohtwq34htowmhtwuwih3tihwo3iht'

#构建鉴权对象
q = Auth(access_key, secret_key)

#初始化BucketManager
bucket = BucketManager(q)

#要上传的空间
bucket_name = 'bucket'

#上传后保存的文件名
key = None

#生成上传 Token,可以指定过期时间等
token = q.upload_token(bucket_name, key, 3600)
# print(token)

#要上传文件的本地路径
localfile = '/home/stonenyy/example.jpg'
ret, info = put_file(token, key, localfile)
# print(info)

#获取远程图片并上传
# url = 'http://qncdn.ttny.net/example.jpg'
# ret, info = bucket.fetch(url, bucket_name, key)
# print(info)

# assert ret['key'] == key
# assert ret['hash'] == etag(localfile)
print(ret['hash'])

发表评论

邮箱地址不会被公开。 必填项已用*标注