Skip to content
heynemann edited this page Jan 11, 2012 · 11 revisions

thumbor uses image storages to perform less retrievals of images from the sources, thus potentially saving expensive resources (such as outbound network).

Pre-Packaged Storages

thumbor comes with filesytem, redis and mongodb storages. There's also a nostorage storage for debugging or benchmarking purposes.

Filesystem Storage

thumbor can store original images in the filesystem. This can potentially lead to file locks, but no extensive testing has been done to confirm it.

The file storage uses the FILE_STORAGE_ROOT_PATH configuration to save the images. It then joins the original image part of the URI to create the proper path to store the image in the filesystem.

There's a STORAGE_EXPIRATION_SECONDS option that will determine the time in seconds that a file is considered to be expired. When a file is expired, thumbor will try to retrieve the file using the specified Image Loader.

To use the filesystem storage set the configuration option of STORAGE to 'thumbor.storages.file_storage'.

Redis Storage

The thumbor team strongly advises the usage of Redis (http://redis.io/) as a storage, since it is REALLY fast and has built-in features that help us invalidate old image originals.

Redis eliminates the risks of locks as well. In order to use the redis storage set the configuration option of STORAGE to 'thumbor.storages.redis_storage'.

You also need to configure the redis connection information using the REDIS_STORAGE_SERVER_PORT, REDIS_STORAGE_SERVER_HOST and REDIS_STORAGE_SERVER_DB, like this:

REDIS_STORAGE_SERVER_HOST = 'localhost'
REDIS_STORAGE_SERVER_PORT = 6379
REDIS_STORAGE_SERVER_DB = 0

There's a STORAGE_EXPIRATION_SECONDS option that will determine the time in seconds that a file is considered to be expired. When a file is expired, thumbor will try to retrieve the file using the specified Image Loader.

MongoDB Storage

MongoDB (http://www.mongodb.org/) eliminates the risks of locks as well. In order to use the mongo storage set the configuration option of STORAGE to 'thumbor.storages.mongo_storage'.

You also need to configure the mongo connection information using the MONGO_STORAGE_SERVER_PORT, MONGO_STORAGE_SERVER_HOST, MONGO_STORAGE_SERVER_DB and MONGO_STORAGE_SERVER_COLLECTION, like this:

MONGO_STORAGE_SERVER_HOST = 'localhost'
MONGO_STORAGE_SERVER_PORT = 27017
MONGO_STORAGE_SERVER_DB = 0
MONGO_STORAGE_SERVER_COLLECTION = 'images'

There's a STORAGE_EXPIRATION_SECONDS option that will determine the time in seconds that a file is considered to be expired. When a file is expired, thumbor will try to retrieve the file using the specified Image Loader.

NoStorage Storage

This is a storage intended for debugging or benchmarking purposes. It does not store any images and always returns None when thumbor asks for an image.

In order to use this storage set the configuration option of STORAGE to 'thumbor.storages.no_storage'.

MixedStorage Storage

This is a storage intended for scenarios where you want to store the original images files one way and the security key another.

A good example would be storing files in the filesystem, while storing security keys in a database.

In order to use this storage set the configuration option of STORAGE to 'thumbor.storages.mixed_storage'.

You must specify the MIXED_STORAGE_FILE_STORAGE, MIXED_STORAGE_CRYPTO_STORAGE and MIXED_STORAGE_DETECTOR_STORAGE options to define the original images storage, the security key storage and the detector results storage, respectively. Here's a sample configuration:

MIXED_STORAGE_FILE_STORAGE = 'thumbor.storages.file_storage'
MIXED_STORAGES_CRYPTO_STORAGE = 'thumbor.storages.redis_storage'
MIXED_STORAGES_DETECTOR_STORAGE = 'thumbor.storages.redis_storage'

FILE_STORAGE_ROOT_PATH = '/tmp/mypath'

REDIS_STORAGE_SERVER_HOST = 'localhost'
REDIS_STORAGE_SERVER_PORT = 6379
REDIS_STORAGE_SERVER_DB = 0

As you can see, you still have to tell thumbor the specific configurations for each storage you choose.

Custom Storages

If the built-in storages do not suit your needs, you can always implement your own storage and use it in the STORAGE configuration.

All you have to do is create a class called Storage that inherits from BaseStorage in your module, as can be seen in https://github.com/globocom/thumbor/blob/master/thumbor/storages/file_storage.py.

Clone this wiki locally