python - 如何将文件上传到 S3 并使用 boto3 将其公开?

标签 python amazon-s3 boto boto3

我可以使用以下方法上传图像文件:

s3 = session.resource('s3')
bucket = s3.Bucket(S3_BUCKET)
bucket.upload_file(file, key)

但是,我也想公开文件。我尝试查找一些函数来为文件设置 ACL,但似乎 boto3 更改了它们的 API 并删除了一些函数。有没有办法在最新版本的 boto3 中做到这一点?

最佳答案

要一步上传并设置公开可读的权限,您可以使用:

bucket.upload_file(file, key, ExtraArgs={'ACL':'public-read'})

https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html#the-extraargs-parameter

关于python - 如何将文件上传到 S3 并使用 boto3 将其公开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41904806/

相关文章:

python - 识别以口语介绍开头的 MP3 文件中钢琴音乐的开头,并使用 Python 删除口语部分

python - 将乘法结果保存到现有数组

python + urllib2 : streaming ends prematurely

python - 如何查找 S3 存储桶内文件夹的大小?

python - 博托服务器错误 : 400 Bad Request: Mail is not sending

amazon-web-services - SES 错误缺少最终 '@domain'

python - 如何计算 Scipy 中多元高斯分布的概率?

emacs - emacs 是否可以从 Amazon S3 存储桶加载缓冲区?

ruby-on-rails-3 - 在 S3 存储桶中设置对象的所有者

java - 使用 SDK 对 AWS S3 存储桶中的对象进行计数时计数不正确