1

我的工作流程有一个从 S3 下载的 tar 文件,然后我可以选择将其上传到冰川保险库中。鉴于 S3 存储桶中还有其他文件,我不想使用生命周期管理。我在 boto 下完成了所有这些工作,现在正在慢慢升级到 boto3

我最近发现,我可以下载到一个字符串对象并对其进行操作,而不是下载到磁盘上的文件,这使得解压缩速度更快,因为我不需要接触磁盘。

s3 = boto3.client('s3')
response = s3.get_object(Bucket=bucket,Key=path)
my_file = tarfile.open(fileobj=(StringIO(response['Body'].read())))
my_file.extractall(path="EXTRACTPATH")

如果我想通过 boto3 上传到冰川,这就是我所拥有的:

glacier = boto3.client('glacier', region_name='MYREGION')
archive = glacier.upload_archive(vaultName='MYVAULT', archiveDescription=filename, body=response['Body'].read())

这让我很清楚:

botocore.exceptions.ClientError: An error occurred (InvalidParameterValueException) when calling the UploadArchive operation: Invalid Content-Length: 0

有什么想法吗?

4

1 回答 1

1

StreamingBody是一个不可搜索的流,它直接从套接字读取,所以你只能得到一个read. 如果要在多个位置使用它们,则需要保存字节。

于 2016-03-25T19:04:37.553 回答