from src.ossConfig import ossConfig
import unicloud_oss.Oss as Oss access_key = 'XXXXXXXXX' secret_key = 'XXXXXXXXXXXXXXXXXXX' endpoint_url = 'http://XXXXXXXXXXXXXXXXX.com' config = ossConfig(access_key,secret_key,endpoint_url) bucket_name = 'test1' object_name = 'myMultipartTest' path = 'D:\\test\\1084.iso' #初始化分片上传 UploadId = Oss.create_multipart_upload(config,bucket_name,object_name) print(UploadId) #获取分片列表 list_parts = Oss.list_parts(config,bucket_name,object_name,UploadId=UploadId) print(list_parts) list_multipart_uploads = Oss.list_multipart_uploads(config,bucket_name) print(list_multipart_uploads) #取消分片上传(删除已上传的分片碎片) if Oss.abort_multipart_upload(config,bucket_name,object_name,UploadId=UploadId): print("abort success") else: print("abort fail!") #文件分片 chunksize = 100*1024*1024 src = open(path,'rb') chunkNum = 1 parts_info={'Parts':[]} while True: chunk = src.read(chunksize) if not chunk: break #上传分片 part = Oss.upload_part(config,bucket_name,object_name,chunk,partNumber = chunkNum,UploadId=UploadId) part_info = { 'ETag':part['ETag'], 'PartNumber':chunkNum, } print(part_info) parts_info['Parts'].append(part_info) chunkNum = chunkNum + 1 src.close() #完成分片上传 if Oss.complete_multipart_upload(config,bucket_name,object_name,parts_info,UploadId=UploadId): print("multipart upload success!") else: print("multipart upload fail!")
|