我使用boto3(Amazon Web Services的python软件包)将zip文件上传到存储桶。它会自动将此zip文件拆分为多个部分并上传。
s3 = get_resource() # This function returns the resource
GB = 1024 ** 3
# Ensure that multipart uploads only happen if the size of a transfer
# is larger than S3's size limit for nonmultipart uploads, which is 5 GB.
config = TransferConfig(multipart_threshold=5 * GB)
s3.meta.client.upload_file("AllPublicXML.zip", "vg-clinicaltrails2", "AllPublicXML_{}.zip".format(output_file_id), Config=config)
print ("S3 Uploading successful")
像魅力一样工作。现在,我使用以下方式下载它:
s3 = get_resource()
GB = 1024 ** 3
config = TransferConfig(multipart_threshold=5 * GB)
list_all_objects_resource(s3, "vg-clinicaltrails2")
print("S3 download Starting for AllPublicXML_{}.zip".format(zip_file_id))
s3.meta.client.download_file("vg-clinicaltrails2", "AllPublicXML_{}.zip".format(zip_file_id), "temp_AllPublicXML.zip", Config=config)
print ("S3 download successful")
这将下载文件并将其另存为temp_AllPublicXML.zip
。我认为该文件尚未通过多部分下载进行整理。如果我使用bash命令unzip temp_AllPublicXML.zip
,则会收到响应:
Archive: temp_AllPublicXML.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of temp_AllPublicXML.zip or
temp_AllPublicXML.zip.zip, and cannot find temp_AllPublicXML.zip.ZIP, period.
如何将这个文件放回原处或具有boto3的下载功能?
预先感谢
编辑:
为澄清起见,如果可能的话,我需要一个纯python解决方案,以及下载后的完整zip文件,而不是提取的文件本身。