python - 将文件从存储桶移动到另一个存储桶/文件夹

标签 python amazon-s3 boto aws-sdk

我想将文件从存储桶移动到同一个存储桶/文件夹。

test 文件夹已存在。

srcBucket = "tmp"
dstBucket = "tmp"
import boto
c = boto.connect_s3()
src = c.get_bucket(srcBucket)
dst = c.get_bucket(dstBucket)
print dst
for k in src.list():
# copy stuff to your destination here
    dst.copy_key(k.key, src.name, "/test/"+k.key)

我得到:

<Message>The specified key does not
exist.</Message><Key>/test/00hbgelokd2i5nglv6opbte003gorrnahv65uo81</Key>

最佳答案

S3 中的对象键不以 / 开头。

http://example-bucket.s3.amazonaws.com/foo/bar.txt 上的对象的键是 foo/bar.txt,而不是/foo/bar.txt

因此,在您的示例中,"/test/"+k.key 应该是 "test/"+k.key

关于python - 将文件从存储桶移动到另一个存储桶/文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33616585/

相关文章:

python - 迭代器的意外行为

amazon-web-services - 使用 JWT 进行自定义身份验证以从 S3 下载

android - AWS S3 安卓开发工具包 2.11.0

amazon-web-services - Firehose 输出到 s3 - 从年月日小时文件夹格式重新分区为 dt=YY-MM-DD 格式

amazon-web-services - 有多个 s3 存储桶还是一个带有子文件夹的存储桶更好?

amazon-web-services - Boto3 : Invalid IAM Instance Profile ARN when calling client. Associate_iam_instance_profile

python - 对导入及其使用方法的困惑

python - 不匹配不是 Python 中的 NoneType 条件

python - 如何将 Amazon S3 存储桶中的 URL 存储在 Django sqlite 数据库中以进行显示和评论?

python - 在 Python 中计算二叉搜索树中的节点