multipart_upload_4.py 968 B

12345678910111213141516171819202122232425
  1. def get_upload_id_list(self):
  2. """
  3. 获取桶内是否存在未完成的multipart
  4. :return: 未完成 upload id list
  5. """
  6. upload_id_list = []
  7. res = self.s3_client.list_multipart_uploads(Bucket=DESTINATION_BUCKET)
  8. try:
  9. # 如果桶内不存在未完成的分片上传,response里就不存在 Uploads 字段
  10. for upload_info in res["Uploads"]:
  11. upload_id_list.append(
  12. {
  13. "Key": upload_info["Key"],
  14. "Initiated": upload_info["Initiated"],
  15. "UploadId": upload_info["UploadId"]
  16. }
  17. )
  18. print ("存在未完成分片 对象名 : {}, 初始化上传时间 : {}".format(upload_info["Key"], upload_info["Initiated"]))
  19. except Exception as e:
  20. # TODO 后面需要确定是哪种异常类型
  21. print ("桶 {} 没有未完成的分片上传".format(DESTINATION_BUCKET))
  22. return upload_id_list