Report this

What is the reason for this report?

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

Posted on February 26, 2018

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.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.