本文整理汇总了Python中sinastorage.bucket.SCSBucket.complete_multipart_upload方法的典型用法代码示例。如果您正苦于以下问题:Python SCSBucket.complete_multipart_upload方法的具体用法?Python SCSBucket.complete_multipart_upload怎么用?Python SCSBucket.complete_multipart_upload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sinastorage.bucket.SCSBucket
的用法示例。
在下文中一共展示了SCSBucket.complete_multipart_upload方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: multipartUpload
# 需要导入模块: from sinastorage.bucket import SCSBucket [as 别名]
# 或者: from sinastorage.bucket.SCSBucket import complete_multipart_upload [as 别名]
def multipartUpload(self):
try:
self.mutex.lock()
self.state = RunnableState.RUNNING
self.useMultipartUpload = True
import math
from sinastorage.multipart import FileChunkWithCallback
min_bytes_per_chunk = 5 * 1024 * 1024 #每片分片最大文件大小
s = SCSBucket(self.bucketName)
keyName = '%s%s'%(self.prefix,os.path.basename(self.filePath))
self.multipart = s.initiate_multipart_upload(keyName, acl=None, metadata={},
mimetype=None, headers={})
self.operationList.append({u'response':self.multipart.init_multipart_response,
u'operation_name':u'初始化分片上传',
u'result':u'完成'})
bytes_per_chunk = max(int(math.sqrt(min_bytes_per_chunk) * math.sqrt(self.source_size)),
min_bytes_per_chunk)
chunk_amount = int(math.ceil(self.source_size / float(bytes_per_chunk)))
self.multipart.bytes_per_part = bytes_per_chunk
self.multipart.parts_amount = chunk_amount
i = 0
for part in self.multipart.get_next_part():
if self.state == RunnableState.DID_CANCELED:
raise sinastorage.bucket.ManualCancel('operation abort')
offset = i * bytes_per_chunk
remaining_bytes = self.source_size - offset
chunk_bytes = min([bytes_per_chunk, remaining_bytes])
self._current_fileChunkWithCallback = FileChunkWithCallback(self.filePath, 'rb', offset=offset,
bytes=chunk_bytes, cb=self.multipartUploadCallBack,
upload_id=self.multipart.upload_id, part_num=part.part_num)
try:
part_result = _upload_part_by_fileWithCallback(self.bucketName, keyName,
self.multipart, part,
self._current_fileChunkWithCallback, None)
self.multipart.parts.append(part_result)
self.operationList.append({u'response':part_result.response,
u'operation_name':u'分片上传%d'%part_result.part_num,
u'result':u'完成'})
finally:
self._current_fileChunkWithCallback.close()
i = i + 1
if len(self.multipart.parts) == chunk_amount:
scsResponse = s.complete_multipart_upload(self.multipart)
self.multipart.complete_multipart_response = scsResponse
self.operationList.append({u'response':scsResponse,
u'operation_name':u'合并分片',
u'result':u'完成'})
# key = s.get_key(keyName)
# key.set_acl(acl)
else:
print len(self.multipart.parts) , chunk_amount
raise RuntimeError("multipart upload is failed!!")
except SCSError, e:
self.response = SCSResponse(e.urllib2Request, e.urllib2Response)
if isinstance(e, ManualCancel): #手动取消
self.state = RunnableState.DID_CANCELED
self.response._responseBody = u'手动取消'
self.emitter.emit(QtCore.SIGNAL("fileUploadDidCanceled(PyQt_PyObject,PyQt_PyObject)"), self, e.msg)
else:
self.state = RunnableState.DID_FAILED
self.response._responseBody = e.data
self.emitter.emit(QtCore.SIGNAL("fileUploadDidFailed(PyQt_PyObject,PyQt_PyObject)"), self, e.msg)
return