小编Ash*_*uGG的帖子

如何使用 python 和 boto3 检查 S3 存储桶中是否存在特定目录

如何检查 S3 中的特定目录中是否存在特定文件?我使用 Boto3 并尝试了这段代码(不起作用):

import boto3

s3 = boto3.resource('s3')
bucket = s3.Bucket('my-bucket')
key = 'dootdoot.jpg'
objs = list(bucket.objects.filter(Prefix=key))
if len(objs) > 0 and objs[0].key == key:
    print("Exists!")
else:
    print("Doesn't exist")
Run Code Online (Sandbox Code Playgroud)

amazon-s3 python-3.x boto3

22
推荐指数
4
解决办法
5万
查看次数

标签 统计

amazon-s3 ×1

boto3 ×1

python-3.x ×1