multipart_upload_10.py 996 B

12345678910111213141516171819202122232425262728293031
  1. def upload_virtual_file_thread(self, upload_id, part_number, upload_body, total):
  2. """
  3. :param upload_id: multipart upload id
  4. :param part_number: 分片数
  5. :param upload_body: 虚拟文件分片内容
  6. :param total:总分片量
  7. :return:
  8. """
  9. print( "Uploading {} / {}".format(part_number, total))
  10. retry_time = 0
  11. while retry_time <= MAX_RETRY_TIME:
  12. try:
  13. self.s3_client.upload_part(
  14. Body=upload_body,
  15. Bucket=DESTINATION_BUCKET,
  16. Key=MULTIPART_UPLOAD_FILE_NAME,
  17. PartNumber=part_number,
  18. UploadId=upload_id
  19. )
  20. break
  21. except Exception as e:
  22. retry_time += 1
  23. if retry_time > MAX_RETRY_TIME:
  24. print ("已达最大重传次数 {},退出".format(retry_time))
  25. sys.exit(-1)
  26. time.sleep(5)
  27. print (" Complete {} / {} ".format(part_number, total))