multipart_upload_13.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. def complete_upload(self, upload_id, len_index_list):
  2. """
  3. 合并分片
  4. :param upload_id:
  5. :param len_index_list:
  6. :return:
  7. """
  8. uploaded_list_parts_clean = []
  9. part_number_marker = 0
  10. is_truncated = True
  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_object in res["Parts"]:
  23. e_tag = part_object["ETag"]
  24. part_number = part_object["PartNumber"]
  25. add_up = {
  26. "ETag": e_tag,
  27. "PartNumber": part_number
  28. }
  29. uploaded_list_parts_clean.append(add_up)
  30. part_number_marker = next_part_number_marker
  31. if len(uploaded_list_parts_clean) != len_index_list:
  32. print ("以上传分片数量与源文件分片数量不匹配!!!")
  33. sys.exit(-1)
  34. complete_struck_json = {
  35. "Parts": uploaded_list_parts_clean
  36. }
  37. res = self.s3_client.complete_multipart_upload(
  38. Bucket=DESTINATION_BUCKET,
  39. Key=MULTIPART_UPLOAD_FILE_NAME,
  40. UploadId=upload_id,
  41. MultipartUpload=complete_struck_json
  42. )