I've used Django-Cookiecutter's default setup for Heroku, with Whitenoise serving static files and S3 serving media files.
However, I want to use 'media' to store certain, heavier content files (pdfs) that are going to change over time, not just user file uploads, and a change shouldn't require a collectstatic. (Eventually I'll create an authoring tool to upload files to S3, but for the moment I'm just manually placing some files like pdfs in correct S3 bucket subdirectories.)
The standard setup for Django-Cookiecutter is to set the MEDIA_URL to the full S3 address, like https://my-bucket.s3.amazonaws.com/media/some.pdf
... but I want to access these files in my templates using relative path like /media/some.pdf
in the same way I can browse directly to static content via /static
.
I want a relative URL like /media/some.pdf
because I'm using the download
attribute on the href tag, which should download the file when clicked, but with a fully qualified url pointing at amazonaws.com, the browser will ignore the download attribute and just load the file in the browser.
Is there a straightforward way to config Django (running on Heroku using Whitenoise for static and S3 for media) to return the file from S3 when accessed via /media
?