Open jeanluc243 opened 6 years ago
See also: #1053
Is this still a requested feature @jeanluc243? I could knock this out this week.
Have static working and triaging one last bug with media. Will push this week
Have static working and triaging one last bug with media. Will push this week
Same problem. I don't know why, but media folder files always is private files. I tried to change class rights, but nothing changed:
class MediaRootS3Boto3Storage(S3Boto3Storage):
location = "media"
default_acl = "public-read"
file_overwrite = False
Any ideas?
I think i found a solution, but need to be reproduced again. First of all need to update DO settings (Spaces -> Select a space -> Settings -> CORS Configurations):
My .envs/.production/.django:
# DigitalOcean Spaces
DJANGO_AWS_ACCESS_KEY_ID=key is here (removed)
DJANGO_AWS_SECRET_ACCESS_KEY=key is here (removed)
DJANGO_AWS_STORAGE_BUCKET_NAME=storage name
#DJANGO_AWS_S3_REGION_NAME=fra1
DJANGO_AWS_S3_ENDPOINT_URL=https://(storage name).fra1.digitaloceanspaces.com
DJANGO_AWS_LOCATION=fra1
My production config settings for STATIC and MEDIA (config/settings/production.py):
# STORAGES
# ------------------------------------------------------------------------------
# https://django-storages.readthedocs.io/en/latest/#installation
INSTALLED_APPS += ["storages"] # noqa F405
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_ACCESS_KEY_ID = env("DJANGO_AWS_ACCESS_KEY_ID")
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_SECRET_ACCESS_KEY = env("DJANGO_AWS_SECRET_ACCESS_KEY")
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_STORAGE_BUCKET_NAME = env("DJANGO_AWS_STORAGE_BUCKET_NAME")
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_QUERYSTRING_AUTH = False
# DO NOT change these unless you know what you're doing.
_AWS_EXPIRY = 60 * 60 * 24 * 7
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_S3_OBJECT_PARAMETERS = {
"CacheControl": f"max-age={_AWS_EXPIRY}, s-maxage={_AWS_EXPIRY}, must-revalidate"
}
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_DEFAULT_ACL = None
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
AWS_S3_REGION_NAME = env("DJANGO_AWS_S3_REGION_NAME", default=None)
AWS_S3_ENDPOINT_URL = env('DJANGO_AWS_S3_ENDPOINT_URL')
AWS_LOCATION = env('DJANGO_AWS_LOCATION')
# STATIC
# ------------------------------------------------------------------------------
STATICFILES_STORAGE = "config.settings.production.StaticRootS3Boto3Storage"
STATIC_URL = f"https://{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/static/"
# MEDIA
# ------------------------------------------------------------------------------
# region http://stackoverflow.com/questions/10390244/
# Full-fledge class: https://stackoverflow.com/a/18046120/104731
from storages.backends.s3boto3 import S3Boto3Storage # noqa E402
class StaticRootS3Boto3Storage(S3Boto3Storage):
location = "static"
default_acl = "public-read"
class MediaRootS3Boto3Storage(S3Boto3Storage):
location = "media"
default_acl = "public-read"
#file_overwrite = False
# endregion
DEFAULT_FILE_STORAGE = "config.settings.production.MediaRootS3Boto3Storage"
MEDIA_URL = f"https://{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/media/"
I don't know, what is right solution, because i also removed file_overwrite = False
.
Is this issue still open, if yes i would like to work on it
I think so @tuhinmallick: Running into issues with digital oceans spaces, django 4.2 and cookie cutter. Looks like my images are being uploaded to one location but the object.attribute.url is pointing to a different location.
Same as @ethanitovitch . This doesn't work in Django 4.2 and higher.
Description
those who do not use AWS s3 but use Digitalocean spaces have trouble deploying static and media, the configurations are a little different.
Solution