【发布时间】:2021-11-19 15:35:10
【问题描述】:
如何检查特定文件是否存在于我的 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")
【问题讨论】:
标签: python-3.x amazon-s3 boto3