如何使用python boto3更新AWS S3中现有对象的元数据? [英] How to update metadata of an existing object in AWS S3 using python boto3?

查看:264
本文介绍了如何使用python boto3更新AWS S3中现有对象的元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

boto3文档没有明确指定如何更新已经存在的S3对象的用户元数据.

boto3 documentation does not clearly specify how to update the user metadata of an already existing S3 Object.

推荐答案

可以使用copy_from()方法-

It can be done using the copy_from() method -

import boto3

s3 = boto3.resource('s3')
s3_object = s3.Object('bucket-name', 'key')
s3_object.metadata.update({'id':'value'})
s3_object.copy_from(CopySource={'Bucket':'bucket-name', 'Key':'key'}, Metadata=s3_object.metadata, MetadataDirective='REPLACE')

这篇关于如何使用python boto3更新AWS S3中现有对象的元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆