After having read James Bennett's article on Django Media and Performance I decided that I wanted to be using S3 for storing and serving media for a new site that I'm working on (in Django)

So, it seems that it's not that easy. I did first of all experiment with using FUSE, but decided against it.

Anyway, looking through some obscure documentation, I found that Django can use custom storage methods. So, I thought I'd write one.

You can find the file here

The code requires you to have Amazon's S3 API installed.

So, how do you use it? It's pretty simple really. First of all - you need to setup your configuration - so edit and add the following (changing the values to suit your needs!)

    'bucket': 'bucket_name',
    'default_perm': 'public-read',
    'vanity_url': False

The settings should be self-explanatory - apart from 'vanity_url'. S3 allows you to CNAME a domain name to a bucket with a similar name - for example, I could CNAME to and it would allow me to serve information from that bucket as if they were coming from my own domain. (infact, I'm tempted to do this - I've too much stuff in my files section!) - the vanity_url - when set to True - will use the bucketname as the domain instead of <bucketname>

Now, to use it in a model, it's as simple as adding an import line at the top of the models file

from import S3Storage

and then, in your model

class Item(models.Model):
    storage = S3Storage()
    image = models.ImageField(upload_to='path', storage=storage)

Pretty simple, :D

Hope this helps some people out there!