如何检查 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)