python - 如何在 put_object 中指定标记?
问题描述
我需要使用 put_object 指定标记,如下所示:
s3client = boto3.client('s3')
response = s3client.put_object(Bucket = dest_bucket_name, Body = body, Key = dest_key, Tagging = tagging, ACL = acl )
我的问题是我使用什么数据结构来标记变量?
我见过各种各样的例子,但我无法让它们发挥作用。例如:
tagging = {'TagSet' : [
{
'Key': 'voiceid',
'Value': polly_voice
},
{
'Key': 'author',
'Value': book_author
},
. . .
]
}
给我
"errorMessage": "Parameter validation failed:\nInvalid type for parameter Tagging, value: {'TagSet': [{'Key': 'voiceid', 'Value': 'Matthew'}, {'Key': 'author', 'Value': 'some guy'},...]}, type: <class 'dict'>, valid types: <class 'str'>"
我看到它需要一个字符串,但是如何指定键:值对?我发现的所有示例都使用了一些特定的数据结构,例如我的示例。
我怀疑这有什么不同,但我在 lambda 函数中这样做。
解决方案
要使其正常工作,请尝试以下代码:
tags = 'voiceid={}&author={}'.format(polly_voice, book_author)
s3client = boto3.client('s3')
response = s3client.put_object(
Bucket=dest_bucket_name,
Body=body,
Key=dest_key,
Tagging=tags
)
您也可以参考这个stackoverflow 答案。
推荐阅读
- html - 为什么我的页脚没有从 html 的边缘增加?
- python - Python Graph API 请求仅从电子邮件中检索 1 个附件
- c++ - 即使某些数字匹配,程序也始终显示 0 个匹配项
- javascript - 检查元素是否存在并获取属性
- python - 如何在 Python 中使用带有 if/else 的列表
- python - 多处理 - 进程似乎没有并行执行
- python - 如何在python中发送301 Moved Permanently响应?
- c# - 在 Winforms 中创建项目及其属性的可滚动列表
- flutter - 抖音滑动效果:如何全屏垂直滚动?
- php - 如何在四个条件状态下查看提前 2 个月之前的日期