本文整理匯總了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)