Skip to main content

Django custom storage for Thumbor backend.

Project description

https://coveralls.io/repos/Starou/django-thumborstorage/badge.png?branch=master https://img.shields.io/pypi/v/django-thumborstorage.svg Travis C.I.

A Django custom storage for Thumbor backend.

This app provide 2 classes ThumborStorage and ThumborMigrationStorage. The last one is a storage you can use for Imagefield initialy using a FileSystemStorage you want to migrate to Thumbor without batch-moving all of them. That way, Django continues to serve them from the file system until you change the image on that field.

Install

pip install django-thumborstorage

Dependencies

Recommended:

Usage

settings.py

Add django_thumborstorage in your INSTALLED_APPS.

And set the following:

THUMBOR_SERVER = 'http://localhost:8888'
THUMBOR_SECURITY_KEY = 'MY_SECURE_KEY'
# This may be a different host than THUMBOR_SERVER
# only reachable by your Django server.
THUMBOR_RW_SERVER = 'http://localhost:8888'

models.py

Just set the storage parameter in the ImageField you want to manage with Thumbor:

from django_thumborstorage.storages import ThumborStorage

class Stuff(models.Model):
    def upload_path(instance, filename):
        return 'stuffs/%s' % filename
    photo = models.ImageField(upload_to=upload_path,
                              storage=ThumborStorage(),
                              height_field='photo_height',
                              width_field='photo_width')
    photo_height = models.IntegerField(blank=True, null=True)
    photo_width = models.IntegerField(blank=True, null=True)

In the code

You can get the Thumbor uuid from the <ImageField> instance using:

my_stuff.photo.storage.key(my_stuff.photo.name)

This is useful to generate_url() with Django-thumbor when original files are stored on Thumbor. Thus, you can pass the key as url parameter.

CHANGELOG

1.11.0

  • Drop support for Django < 1.11 and Python 3.4.

  • Remove mock from dependencies.

0.92.2

  • Fix readonly_to_rw_url() to manage suffix in the urls.

0.92.1

  • Handle status code of the Thumbor server response when posting an image.

0.92.0

  • Added experimental Python 3.4 support (Thanks to Charlie 123.)

  • Fixed broken support for Django < 1.7 (Thanks to Rizziepit.)

  • Added unicode support in file names (Thanks to Rizziepit.)

0.91.6

  • Add storages.readonly_to_rw_url(), a function to convert a read-only thumbor url in a rw url.

0.91.5

  • Use THUMBOR_SERVER to generate the original file url.

Backward imcompatibilities

  • THUMBOR_SERVER and THUMBOR_SECURITY_KEY are required in settings.

0.91.4

  • Add ThumborStorage.key(name) to retrieve the Thumbor uuid from the name.

0.91.3

Backward imcompatibilities

  • THUMBOR_WRITABLE_SERVER setting is replaced by THUMBOR_RW_SERVER since it is now used to retrieve the original file.

TODO

  • PUT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-thumborstorage-1.11.1.tar.gz (126.8 kB view details)

Uploaded Source

File details

Details for the file django-thumborstorage-1.11.1.tar.gz.

File metadata

  • Download URL: django-thumborstorage-1.11.1.tar.gz
  • Upload date:
  • Size: 126.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.10

File hashes

Hashes for django-thumborstorage-1.11.1.tar.gz
Algorithm Hash digest
SHA256 167a15200f957eaaa6a105584880a63a4d8c985f5cd078f410fc2a3a8bdfef39
MD5 bfdf9b5c94756bd10bdbce49a8403931
BLAKE2b-256 3bcaf814dd55017b96f858b825163540d569e2590617ee96dab7a56345cec51c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page