Hosting uploaded files only for logged in users

Hosting of static files seems to be a recurring topic, but I could not find a solution to my problem:

I’m just finishing my first small Django app. It is a toy app with a few pages and will not have more than 20-30 users in the near future. But it allows to upload images and those images should only be visible to logged in users.

I’m aware that static files should not be served by the Django app, but by a dedicated web server like Nginx. But the whole “collectstatic” workflow works only for static files that are known upfront like JS and CSS.

I know that with Nginx I could probably get Authentication Based on Subrequest Result | NGINX Documentation to work with Django. But then I have to manage Nginx myself.

But I would prefer to use a “serverless” solution like DigitalOcean, Render, …

Does anybody know a managed solution where I can serve uploaded files in a protected way?

Take a look at the solution documented at Storing Django Static and Media Files on Amazon S3 | TestDriven.io
You may find it suitable for your purposes.

Side note:

For clarity, these are “media” files and not “static” files. They are managed and handled separately. (e.g. the collectstatic command is not involved at all with “media” files.)

1 Like