[英]Django-Storages S3 with minio as backend
i would like to use django-storages with minio so i tryd to adopt settings, configs etc. I found on the web but for some reason my access key or the way it gets provided fails with the following error:我想将 django-storages 与 minio 一起使用,所以我尝试采用设置、配置等。我在网上找到,但由于某种原因,我的访问密钥或提供它的方式失败,并出现以下错误:
botocore.exceptions.ClientError: An error occurred (InvalidAccessKeyId) when calling the PutObject operation: The AWS Access Key Id you provided does not exist in our records.
if i run manage.py collectstatic
如果我运行
manage.py collectstatic
settings.py设置.py
#S3 config
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'MyProject/static'),
]
AWS_ACCESS_KEY_ID = '9VOWWCTSMX4ZEGVW7N9D'
AWS_SECRET_ACCESS_KEY = 'zJFf9BYWk0TM3FVwyY98UFy0o+DQF0oY1vCXgLqV'
AWS_STORAGE_BUCKET_NAME = 'static'
AWS_S3_CUSTOM_DOMAIN = '127.0.0.1:9000'
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
}
AWS_LOCATION = 'static'
STATIC_URL = 'http://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
Is there maybe someone that has already done this?也许有人已经这样做了?
Here is what I did to get it to work这是我为使其正常工作所做的工作
# settings.py
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_STORAGE_BUCKET_NAME = 'static'
AWS_ACCESS_KEY_ID = minio_access_key
AWS_SECRET_ACCESS_KEY = minio_secret_key
AWS_S3_ENDPOINT_URL = minio_address (eg. http://localhost:9000)
Versions:版本:
Note: versions were latest when installed using pip install <package>
注意:使用
pip install <package>
时版本是最新的
I didn't attempt to use django-minio-storage
since it does not support Django3.我没有尝试使用
django-minio-storage
因为它不支持 Django3。
If you have upgraded your package versions, try what I did.如果您升级了软件包版本,请尝试我所做的。 If not try setting
S3_HOST = '127.0.0.1:9000'
.如果没有尝试设置
S3_HOST = '127.0.0.1:9000'
。
AWS_S3_ENDPOINT_URL
from django-storage docs来自django-storage 文档的
AWS_S3_ENDPOINT_URL
AWS_S3_ENDPOINT_URL
(optional: default is None, boto3 only )AWS_S3_ENDPOINT_URL
(可选:默认为 None,仅限 boto3 )
Custom S3 URL to use when connecting to S3, including scheme.连接到 S3 时使用的自定义 S3 URL,包括方案。 Overrides
AWS_S3_REGION_NAME
andAWS_S3_USE_SSL
.覆盖
AWS_S3_REGION_NAME
和AWS_S3_USE_SSL
。 To avoid AuthorizationQueryParametersError error,AWS_S3_REGION_NAME
should also be set.为避免 AuthorizationQueryParametersError 错误,还应设置
AWS_S3_REGION_NAME
。
Troubleshooting故障排除
Disconnect from the internet and run manage.py collectstatic
to see the address to which boto fails to connect.断开 Internet 连接并运行
manage.py collectstatic
以查看 boto 无法连接到的地址。
[This is an assumption]: You are trying to access the minio settings/stuff with minio credential . [这是一个假设]:您正在尝试使用minio credential访问minio 设置/内容。 But, the django-storage package using it on aws s3's API.
但是, django-storage包在 aws s3 的 API 上使用它。
If you are trying to do with minio , you should use minio backed , which is possible by using django-minio-storage如果您尝试使用minio ,则应该使用minio backed ,这可以通过使用django-minio-storage 来实现
I've implemented the media storage and static storage with the help of django-minio-storage in production, and it's working seamlessly.我已经在django-minio-storage的帮助下在生产中实现了媒体存储和静态存储,并且它可以无缝地工作。
DEFAULT_FILE_STORAGE = 'minio_storage.storage.MinioMediaStorage'
STATICFILES_STORAGE = 'minio_storage.storage.MinioStaticStorage'
MINIO_STORAGE_ENDPOINT = '127.0.0.1:9000'
MINIO_STORAGE_STATIC_BUCKET_NAME = "static"
STATIC_URL = f'https://{MINIO_STORAGE_ENDPOINT}/{MINIO_STORAGE_STATIC_BUCKET_NAME}/'
MINIO_STORAGE_USE_HTTPS = True
MINIO_STORAGE_AUTO_CREATE_MEDIA_BUCKET = True
MINIO_STORAGE_AUTO_CREATE_STATIC_BUCKET = True
MINIO_STORAGE_ACCESS_KEY = #your ACCESS_KEY
MINIO_STORAGE_SECRET_KEY = # Your SECRET_KEY
MINIO_STORAGE_MEDIA_BUCKET_NAME = "media"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.