本文整理汇总了Python中qiniu.put_file方法的典型用法代码示例。如果您正苦于以下问题:Python qiniu.put_file方法的具体用法?Python qiniu.put_file怎么用?Python qiniu.put_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qiniu
的用法示例。
在下文中一共展示了qiniu.put_file方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_file
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import put_file [as 别名]
def save_file(self, localfile, filename=None):
# 构建鉴权对象
auth = Auth(self._access_key, self._secret_key)
# 上传到七牛后保存的文件名
key = filename
# 生成上传 Token,可以指定过期时间等
token = auth.upload_token(self._bucket_name)
ret, info = put_file(token, key, localfile)
print(info)
try:
assert ret['key'] == key
assert ret['hash'] == etag(localfile)
except Exception as e:
current_app.logger.info(e)
return ret, info
示例2: upload
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import put_file [as 别名]
def upload(self, picture_path_list, link_only=False):
if self.upload_handler:
success_uploaded_list = []
for picture_path in picture_path_list:
picture_name = os.path.basename(picture_path)
token = self.upload_handler.upload_token(self.container_name, picture_name, 3600)
ret, info = put_file(token, picture_name, picture_path)
bucket = BucketManager(self.upload_handler)
success = bucket.stat(self.container_name, picture_name)
print(success)
self.write_markdown_picture_url(picture_path_list, link_only)
示例3: upload_file_to_qiniu
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import put_file [as 别名]
def upload_file_to_qiniu(file_path, key=None, **kwargs):
bucket_name = kwargs.pop('bucket_name', None)
token = get_qiniu_token(key, bucket_name=bucket_name)
ret, info = put_file(token, key, file_path, **kwargs)
return ret, info
示例4: upload_file_to_qiniu
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import put_file [as 别名]
def upload_file_to_qiniu(file_path, file_name):
print("[%s] uploading......" % file_name)
token = q.upload_token(config['bucket_name'], file_name)
ret, _ = put_file(token, file_name, file_path)
assert ret['key'] == file_name
assert ret['hash'] == etag(file_path)
return os.path.join(config['bucket_url'], ret['key'])
示例5: down
# 需要导入模块: import qiniu [as 别名]
# 或者: from qiniu import put_file [as 别名]
def down(token, key, localfile, mime_type, delete=False):
ret, info = qiniu.put_file(
token, key, localfile,
mime_type=mime_type,
check_crc=True
)
assert ret['key'] == key
assert ret['hash'] == qiniu.etag(localfile)
print(localfile)
if delete:
os.remove(localfile)