Skip to main content
 首页 » 编程设计

python之使用 python 和 boto3 在 s3 中公开一个文件

2025年05月04日26xxx_UU

我需要 boto3 对这个问题的更新 Make a file in s3 public using python and boto

s3.Bucket('gentle-persuader-emoji').put_object(Key=emoji_png_file, Body=image) 
response = s3.object(emoji_png_file).put_object_acl('ACL=public-read') 

给出错误

AttributeError: 's3.ServiceResource' object has no attribute 'object' 

请您参考如下方法:

由于您要上传对象,最简单的方法是在上传过程中指定访问控制列表 (ACL):

s3.Bucket('gentle-persuader-emoji').put_object(Key=emoji_png_file, Body=image, ACL='public-read') 

或者,您可能希望添加 Bucket Policy适用于整个存储桶(或存储桶中的特定路径),而不是将策略应用于每个单独的对象。