【发布时间】:2018-09-22 16:09:05
【问题描述】:
我需要下载 Amazon S3 存储桶的所有内容(包括版本)并上传到其他 Amazon S3 存储桶。不要叫我用aws,我就是不会用。
我为此使用了 tempfile.TemporaryFile,它显然有效,打印显示文件对象内部有正确的内容,但 上传 文件是空的(零字节)。
with tempfile.TemporaryFile() as data:
sourceUser.download_fileobj('source-bucket',key,data)
# next 2 lines was just to check the content of the file
data.seek(0)
print (data.read())
destinationUser.upload_fileobj(data,'destination-bucket',key)
【问题讨论】:
-
在上传前重新寻找偏移量0?还是在文件上打开一个新流?
-
你见过this question吗?
-
@ClaudiuIvanescu 您不必使用任何库直接从一个存储桶复制到另一个存储桶。您可以使用 hmac-sha-256 库和 HTTP 用户代理...或 API Gateway 后面的 Lambda 函数来构建和签署请求并将其发送到 S3。
-
@Michael-sqlbot 很抱歉,我没有足够的知识来做你的事情。 jarmod 显示了错误,现在可以工作了。但我不想拿他的功劳!
-
这也解决了我遇到的一个问题,我需要下载和重新上传(在我的情况下需要进行 CV2 操作)。 tmp.seek(0) 也在这里解决了我的问题。谢谢@jarmod
标签: python python-3.x amazon-web-services amazon-s3