imetting_backend/test_upload.py

21 lines
721 B
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# -*- coding: utf-8 -*-
# flake8: noqa
from qiniu import Auth, put_data ,put_file_v2, etag
import qiniu.config
#需要填写你的 Access Key 和 Secret Key
access_key = 'A0tp96HCtg-wZCughTgi5vc2pJnw3btClwxRE_e8'
secret_key = 'Lj-MSHpaVbmzpS86kMIjmwikvYOT9iPBjCk9hm6k'
#构建鉴权对象
q = Auth(access_key, secret_key)
#要上传的空间
bucket_name = 'imeeting'
#上传后保存的文件名
key = 'test/result.json'
#生成上传 Token可以指定过期时间等
token = q.upload_token(bucket_name, key, 3600)
#要上传文件的本地路径
localfile = './uploads/result.json'
ret, info = put_file_v2(token, key, localfile, version='v2')
print(info)
assert ret['key'] == key
assert ret['hash'] == etag(localfile)