What is the most flexlible and universal way to store media files with Django?

Posted February 26, 2018 2k views
NginxDigitalOceanDjangoApplicationsUbuntu 16.04

I am currently learning web development and I wonder what is the best and most flexible approach to storing media files?
You never know how much will your website grow and because of that, I want to know how to handle big amounts of media files correctly using Django running on a Nginx server.
I tried some googling, but media files handling in production is not that well documented, at least not as well as handling media files in development. Every suggestion will help me.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Really depends on how much searching and organizing you’ll need.

I personally prefer the idea of using a file-key in whatever DB I’m using that way I can experiment with different storage methods while the actual DB lookup keeps my static value. You’ll have to code something to load the actual media from the key, but you won’t have to worry about the two being tied together permanently.

Example: (I personally use mongo for my DB so everything is a JSON)

{ "_id":201,
  "title":"kitten fights lemon",

That way I can just lookup the media.type and media.Key against whatever storage I’m using.

I’m currently loading from Ext4 on debian, but am going to try BtrFS next to see if there is any difference.

  • It actually sounds like a great idea. I will look if there are some ways to do this in Django. I hope I won’t have to fight the framework because that is always a pain.

    Thank you for your suggestion!