Rya*_*IRL 7 python content-type amazon-s3 boto
这是复制S3密钥的一些示例代码.您可能需要执行此操作的原因很多,其中一个原因是更新关键元数据.虽然这似乎是广泛接受的解决方案,但存在一个大问题.问题是,当我执行下面的示例时,实际上我丢失了我的Content-Type,它默认返回'application/octet-stream'(如果尝试提供Web图像则不是很有用).
# Get bucket
conn = S3Connection(self._aws_key, self._aws_secret)
bucket = conn.get_bucket(self._aws_bucket)
# Create key
k = Key(bucket)
k.key = key
# Copy old key
k.metadata.update({ meta_key: meta_value })
k2 = k.copy(k.bucket.name, k.name, k.metadata, preserve_acl=True)
k = k2
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢.
以下GitHub Gist为我工作:
import boto
s3 = boto.connect_s3()
bucket = s3.lookup('mybucket')
key = bucket.lookup('mykey')
# Copy the key onto itself, preserving the ACL but changing the content-type
key.copy(key.bucket, key.name, preserve_acl=True, metadata={'Content-Type': 'text/plain'})
key = bucket.lookup('mykey')
print key.content_type
Run Code Online (Sandbox Code Playgroud)
花了很多时间跑!
| 归档时间: |
|
| 查看次数: |
3424 次 |
| 最近记录: |