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

February 26, 2018 595 views
Nginx Django Applications DigitalOcean Ubuntu 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.

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",
  "author":"CowFu",
  "status":"Published",
  "tags":["kitten","lemon","fight"],
  "thumb":"p1000321",
  "media":{"type":"mov","key":"m874389"}
}

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!

Have another answer? Share your knowledge.