Skip to content
\n

The important part of this is configuring the DEFAULT_FILE_STORAGE to the s3Boto3Storage in your .env:

\n
AWS_ACCESS_KEY_ID=...\nAWS_SECRET_ACCESS_KEY=...\nAWS_STORAGE_BUCKET_NAME=my-bucket\nAWS_S3_REGION_NAME=us-east-1\n\n# This is the important config\nDEFAULT_FILE_STORAGE=storages.backends.s3boto3.S3Boto3Storage\n
\n

With these env variables set I later added an S3 config in the settings:

\n
# S3 storage configuration\nif AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY:\n    # AWS_DEFAULT_ACL = \"public-read\"  # I don't use ACL so I don't use it, but you can have it set here.\n\n    # I generate an S3 custom domain here because I manage multiple projects in a single bucket, but you can generate a static url here.\n    # I just find this to be more organized.\n    AWS_S3_CUSTOM_DOMAIN = (\n        f\"{AWS_STORAGE_BUCKET_NAME}.s3.{AWS_S3_REGION_NAME}.amazonaws.com\"\n    )\n    AWS_LOCATION = \"media\"  # You can change this base on your desire media directory.\n\n    # Media URL will point to S3\n    MEDIA_URL = f\"https://{AWS_S3_CUSTOM_DOMAIN}/{AWS_LOCATION}/\"\n    # I don't set MEDIA_ROOT here since files are provisioned by an s3 url.\n\n    # S3 upload settings\n    AWS_S3_FILE_OVERWRITE = False  # Don't overwrite files with the same name (optional)\n    AWS_QUERYSTRING_AUTH = False  # Don't add query parameters to URLs (optional)\nelse:\n    # If the S3 config fails then I fallback to defaults. Not needed I think but I do it. \n    MEDIA_URL = \"/media/\"\n    MEDIA_ROOT = os.path.join(BASE_DIR, \"media\")\n
\n

By doing this configurations I was able to change the default behavior of the Logo file storage and handle the S3 implementation. This is more of an S3/Django default configurations. But I think it's worth to have it documented somewhere.

","upvoteCount":1,"url":"https://github.com/fabiocaccamo/django-admin-interface/discussions/383#discussioncomment-12495601"}}}

Logos in media folder #383

Answered by cor14095
hcwinsemius asked this question in Q&A
Apr 18, 2024 · 2 comments · 8 replies
Discussion options

You must be logged in to vote

Hi, I stumble through this issue and got around it kinda simple. But It was hard for me to figure out the pieces so I'll leave this here and look to open a PR to enhance documentarion.

First of all in my settings.py I have something like this:

# AWS Configuration
    AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
    AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
    AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME", "example-bucket")
    AWS_S3_REGION_NAME = os.getenv("AWS_S3_REGION_NAME", "us-east-1")

# Default file storage (This is kinda the important part)
    DEFAULT_FILE_STORAGE = os.getenv("DEFAULT_FILE_STORAGE", "django.core.files.storage.FileSystemSto…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
2 replies
@hcwinsemius
Comment options

@fabiocaccamo
Comment options

Comment options

You must be logged in to vote
6 replies
@cor14095
Comment options

@merwok
Comment options

@cor14095
Comment options

@merwok
Comment options

@fabiocaccamo
Comment options

Answer selected by fabiocaccamo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request
4 participants