Question

I have a high load django project with a lot of images in it (in django.db.models.ImageField). I'm looking for a solution with the following criteria:

  1. Images are stored in Rackspace CloudFiles (using django-cumulus)
  2. Images' thumbnails are stored in cloud too
  3. Thumbnails are generated at the same moment as source image changes (I don't want thumbnails to be generated on template render as most of django's thumbnails libraries do)

I would be grateful for your help.

Was it helpful?

Solution

For (1) you should be able to use django-cumulus, I'm not aware of another working package for Rackspace CloudFiles.

For (2) set the STATICFILES_STORAGE setting to point to the class which handles static files on the cloud. In my case I store my user-uploaded static files on Amazon S3, and I extend the S3BotoStorage class imported this way:

from storages.backends.s3boto import S3BotoStorage

from django-storages. Find what the equivalent class is for the django-cumulus module and use/extend accordingly; storage classes are in here. The key is to set STATICFILES_STORAGE to point to it.

For (3) use your thumbnail generation library to "fetch" the image at the various thumbnail sizes you need when the source image changes. This will create them immediately (if they do not exist yet). (This applies for the libraries I have used, which are sorl-thumbnail and easy_thumbnails.

Side note: "asynchronous generation" of thumbnails (so that the initial request does not have to wait for all thumbnails to be generated immediately) is a popular requirement, and it is fairly documented for the easy_thumbnails library here. Should be straightforward to set up if you have celery already enabled in your architecture.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top