multipart_upload_7.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. def check_part_number_list(self, upload_id):
  2. """
  3. 检查是否存在以上传的分片
  4. :param upload_id: 未完成分片上传文件的upload_id
  5. :return:
  6. """
  7. try:
  8. is_truncated = True
  9. part_number_marker = 0
  10. part_number_list = []
  11. while is_truncated:
  12. res = self.s3_client.list_parts(
  13. Bucket=DESTINATION_BUCKET,
  14. Key=MULTIPART_UPLOAD_FILE_NAME,
  15. UploadId=upload_id,
  16. MaxParts=1000,
  17. PartNumberMarker=part_number_marker
  18. )
  19. next_part_number_marker = res["NextPartNumberMarker"]
  20. is_truncated = res["IsTruncated"]
  21. if next_part_number_marker > 0:
  22. for part_number_object in res["Parts"]:
  23. part_number_list.append(part_number_object["PartNumber"])
  24. part_number_marker = next_part_number_marker
  25. if part_number_list:
  26. print ("已存在上传分片 : {}".format(part_number_list))
  27. except Exception as e:
  28. print ("Exception error {}, quit \n".format(e.message))
  29. sys.exit(-1)
  30. return part_number_list