首页 > 解决方案 > Django 存储和 Boto3 未从 AWS S3 检索媒体

问题描述

我正在使用开发服务器来测试使用 Django 存储和 Boto3 从 AWS S3 上传和检索静态文件。文件上传有效,但我无法检索文件。

这就是我得到的:

在此处输入图像描述

当我在另一个选项卡中查看 URL 时,我得到了这个

**This XML file does not appear to have any style information associated with it. The document tree is shown below.**
<Error>
<Code>IllegalLocationConstraintException</Code>
    <Message>The me-south-1 location constraint is incompatible for the region specific endpoint this request was sent to.</Message>
    <RequestId></RequestId>
    <HostId></HostId>
</Error>

我还用我自己的凭证和 IAM 用户配置了 settings.py

AWS_ACCESS_KEY_ID = <key>
AWS_SECRET_ACCESS_KEY = <secret-key>
AWS_STORAGE_BUCKET_NAME = <bucket-name>
AWS_DEFAULT_ACL = None
AWS_S3_FILE_OVERWRITE = False
AWS_S3_REGION_NAME = 'me-south-1'
AWS_S3_USE_SSL = True
AWS_S3_VERIFY = False
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

标签: djangoamazon-s3boto3django-storagepython-django-storages

解决方案


请检查您的 AWS Identity & Access Management Console (IAM) 是否为您的访问密钥分配了适当的 S3 权限。

此外,请确保您已安装 AWS CLI 并在您的计算机中设置您的凭证。

您可以尝试运行以下命令并进行验证。

$ aws s3 ls
2018-12-11 17:08:50 my-bucket
2018-12-14 14:55:44 my-bucket2

参考:https ://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html


推荐阅读