【问题标题】:Using boto library on S3在 S3 上使用 boto 库
【发布时间】:2011-09-10 11:49:51
【问题描述】:

有没有办法更改 S3 文件的密钥?例如,我希望能够执行以下操作:

>>> from boto.s3.key import Key
>>> k=Key(bucket)
>>> k.key='cli-images/image-thumb.jpg' # this is the original key
>>> k.key='cli-images/moved/image-thumb.jpg' # this is the key I want to change it to
>>> k.save()

在查看 boto 文档时,我只能找到一种将密钥复制到另一个存储桶的方法,但在这种情况下,我需要将文件保留在同一个存储桶中,只需移动位置(即更改密钥)。谢谢。

【问题讨论】:

    标签: python amazon-s3 boto


    【解决方案1】:

    只需将对象复制到同一个存储桶并删除原始存储桶即可:

    from boto.s3.key import Key
    k=Key(bucket)
    k.key='cli-images/image-thumb.jpg'
    k.copy('bucketname', 'cli-images/moved/image-thumb.jpg')
    k.delete()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-12
      • 2017-08-18
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 2016-09-23
      相关资源
      最近更新 更多