首页 文章

boto3将字符串上传到冰川文件

提问于
浏览
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

有什么想法吗?

1 回答

  • 1

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

相关问题