本文整理匯總了Python中qiniu.put_data方法的典型用法代碼示例。如果您正苦於以下問題:Python qiniu.put_data方法的具體用法?Python qiniu.put_data怎麽用?Python qiniu.put_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qiniu
的用法示例。
在下文中一共展示了qiniu.put_data方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: storage
# 需要導入模塊: import qiniu [as 別名]
# 或者: from qiniu import put_data [as 別名]
def storage(data):
"""七牛雲存儲上傳文件接口"""
if not data:
return None
try:
# 構建鑒權對象
q = Auth(access_key, secret_key)
# 生成上傳 Token,可以指定過期時間等
token = q.upload_token(bucket_name)
# 上傳文件,retult中包含一個key指的是上傳文件的路徑,info中存的是響應信息
ret, info = put_data(token, None, data)
except Exception as e:
logging.error(e)
raise e
if info and info.status_code != 200:
raise Exception("上傳文件到七牛失敗")
# 返回七牛中保存的圖片名,這個圖片名也是訪問七牛獲取圖片的路徑
return ret["key"]
示例2: _save_to_qiniu
# 需要導入模塊: import qiniu [as 別名]
# 或者: from qiniu import put_data [as 別名]
def _save_to_qiniu(self, token, key):
self._source.seek(0)
import qiniu
qiniu.set_default(connection_timeout=self.timeout)
if six.PY3:
# use patched put_data implementation for py3k
ret, info = self._save_to_qiniu_internal_py3(token, key)
else:
# use put_data implementation provided by qiniu-sdk
ret, info = qiniu.put_data(token, key, self._source)
self._source.seek(0)
if info.status_code != 200:
self._save_callback(token, False)
raise LeanCloudError(
1,
"the file is not saved, qiniu status code: {0}".format(
info.status_code
),
)
self._save_callback(token, True)
示例3: upload
# 需要導入模塊: import qiniu [as 別名]
# 或者: from qiniu import put_data [as 別名]
def upload(self, data, path):
token = q.upload_token(self.scope)
data.seek(0)
ret, _ = _q.put_data(token, path, data)
if ret:
return path, ret['hash']
raise UploadFailedError
示例4: _put_file
# 需要導入模塊: import qiniu [as 別名]
# 或者: from qiniu import put_data [as 別名]
def _put_file(self, name, content):
token = self.auth.upload_token(self.bucket_name)
ret, info = put_data(token, name, content)
if ret is None or ret['key'] != name:
raise QiniuError(info)
示例5: save
# 需要導入模塊: import qiniu [as 別名]
# 或者: from qiniu import put_data [as 別名]
def save(self, data, filename=None):
auth = QiniuClass.Auth(self._access_key, self._secret_key)
token = auth.upload_token(self._bucket_name)
return QiniuClass.put_data(token, filename, data)