multipart_upload_9.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. def upload_thread(self, upload_id, part_number, part_start_index, total):
  2. """
  3. :param upload_id: multipart upload id
  4. :param part_number: 分片数
  5. :param part_start_index: 分片在文件的偏移位置
  6. :param total:总分片量
  7. :return:
  8. """
  9. print ("Uploading {} / {}".format(part_number, total))
  10. with open(MULTIPART_UPLOAD_FILE, "rb") as data:
  11. retry_time = 0
  12. while retry_time <= MAX_RETRY_TIME:
  13. try:
  14. data.seek(part_start_index)
  15. self.s3_client.upload_part(
  16. Body=data.read(CHUNK_SIZE),
  17. Bucket=DESTINATION_BUCKET,
  18. Key=MULTIPART_UPLOAD_FILE_NAME,
  19. PartNumber=part_number,
  20. UploadId=upload_id
  21. )
  22. break
  23. except Exception as e:
  24. retry_time += 1
  25. if retry_time > MAX_RETRY_TIME:
  26. sys.exit(-1)
  27. time.sleep(5)
  28. print (" Complete {} / {} ".format(part_number, total))