gpt4 book ai didi

python - 演示如何使用 boto3 从 S3 存储桶中删除一个或多个特定 key

转载 作者:太空宇宙 更新时间:2023-11-03 14:59:59 31 4
gpt4 key购买 nike

boto3 function允许从 S3 存储桶中删除 key 列表。请您演示如何使用它的示例:

  1. 要删除的单个 key 。
  2. 要删除的多个键的列表。

谢谢。

delete_objects(**kwargs)
This operation enables you to delete multiple objects from a bucket using a single HTTP request. You may specify up to 1000 keys.

Request Syntax

response = bucket.delete_objects(
Delete={
'Objects': [
{
'Key': 'string',
'VersionId': 'string'
},
],
'Quiet': True|False
},
MFA='string',
RequestPayer='requester'
)

最佳答案

删除一个对象:

response = bucket.delete_objects(
Delete={
'Objects': [
{
'Key': 'myObjectKey'
}
]
}
)

删除两个对象:

response = bucket.delete_objects(
Delete={
'Objects': [
{
'Key': 'myFirstObjectKey'
},
{
'Key': 'mySecondObjectKey'
}
]
}
)

我觉得文档(您链接的)使这一点非常明显。我很好奇您是如何发现文档令人困惑的。

关于python - 演示如何使用 boto3 从 S3 存储桶中删除一个或多个特定 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38915234/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com