=====================
django-thumborstorage
=====================
.. image:: https://coveralls.io/repos/github/Starou/django-thumborstorage/badge.svg?branch=master
:target: https://coveralls.io/github/Starou/django-thumborstorage?branch=master
.. image:: https://img.shields.io/pypi/v/django-thumborstorage.svg
:target: https://pypi.python.org/pypi/django-thumborstorage
A Django custom storage for Thumbor.
Provides 2 custom storages classes: ``ThumborStorage`` and ``ThumborMigrationStorage``.
Use ``ThumborMigrationStorage`` on an ``Imagefield`` that started with a classic
``FileSystemStorage`` you want to upgrade to Thumbor without migrating your old
media. That way, Django continues to serve them from the file system until the
image is changed.
Install
=======
::
pip install django-thumborstorage
Dependencies
''''''''''''
* Python 3.6+
* Django 2.1 to 3.2
* Requests_
* Libthumbor_
Recommended:
* Django-thumbor_ (to manage thumbnails).
* Thumbor_
Usage
=====
settings.py
'''''''''''
Add ``django_thumborstorage`` in ``INSTALLED_APPS``.
And set the following with your values:
.. code-block:: python
THUMBOR_SERVER = 'https://my.thumbor.server.com: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 = 'https://my.rw.thumbor.server.local:8888'
models.py
'''''''''
Just set the ``storage`` parameter in the ImageField you want to manage with Thumbor:
.. code-block:: python
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:
.. code-block:: python
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
=========
2.0.0
'''''
* Add support for Django 3.2.
Possible breaking change
------------------------
The leading ``/`` in the path of the file stored in the database has been removed
due to a breaking change introduced un Django 3.2.11.
https://docs.djangoproject.com/en/4.0/releases/3.2.11/#cve-2021-45452-potential-directory-traversal-via-storage-save
That release handle seamlessly both pre-2.0.0 style (*/image/...*) and
post-2.0.0 style paths (*image/...*) so there is not need to migrate your database
to replace */image/...* with *image/...*.
1.13.0
''''''
* Drop support for Django < 2.1 and Python 2.7, 3.4 and 3.5
* Use GitHub actions for CI instead of Travis.
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
.. _Requests: http://www.python-requests.org/en/latest/
.. _Thumbor: https://github.com/globocom/thumbor
.. _Libthumbor: https://github.com/heynemann/libthumbor
.. _Django-thumbor: https://django-thumbor.readthedocs.org/en/latest/
Raw data
{
"_id": null,
"home_page": "https://github.com/Starou/django-thumborstorage",
"name": "django-thumborstorage",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Stanislas Guerra",
"author_email": "stanislas.guerra@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/8b/6b/8f1af83872c03cbd8fbb03f728c7a9b6e0ea1878a6877dca715749cc1d49/django-thumborstorage-2.0.0.tar.gz",
"platform": null,
"description": "=====================\ndjango-thumborstorage\n=====================\n\n.. image:: https://coveralls.io/repos/github/Starou/django-thumborstorage/badge.svg?branch=master\n :target: https://coveralls.io/github/Starou/django-thumborstorage?branch=master\n\n.. image:: https://img.shields.io/pypi/v/django-thumborstorage.svg\n :target: https://pypi.python.org/pypi/django-thumborstorage\n\nA Django custom storage for Thumbor.\n\nProvides 2 custom storages classes: ``ThumborStorage`` and ``ThumborMigrationStorage``.\n\nUse ``ThumborMigrationStorage`` on an ``Imagefield`` that started with a classic\n``FileSystemStorage`` you want to upgrade to Thumbor without migrating your old\nmedia. That way, Django continues to serve them from the file system until the\nimage is changed.\n\nInstall\n=======\n\n::\n\n pip install django-thumborstorage\n\nDependencies\n''''''''''''\n\n* Python 3.6+\n* Django 2.1 to 3.2\n* Requests_\n* Libthumbor_\n\nRecommended:\n\n* Django-thumbor_ (to manage thumbnails).\n* Thumbor_\n\nUsage\n=====\n\nsettings.py\n'''''''''''\n\nAdd ``django_thumborstorage`` in ``INSTALLED_APPS``.\n\nAnd set the following with your values:\n\n.. code-block:: python\n\n THUMBOR_SERVER = 'https://my.thumbor.server.com:8888'\n THUMBOR_SECURITY_KEY = 'MY_SECURE_KEY'\n # This may be a different host than THUMBOR_SERVER\n # only reachable by your Django server.\n THUMBOR_RW_SERVER = 'https://my.rw.thumbor.server.local:8888'\n\nmodels.py\n'''''''''\n\nJust set the ``storage`` parameter in the ImageField you want to manage with Thumbor:\n\n.. code-block:: python\n\n from django_thumborstorage.storages import ThumborStorage\n\n class Stuff(models.Model):\n def upload_path(instance, filename):\n return 'stuffs/%s' % filename\n photo = models.ImageField(upload_to=upload_path,\n storage=ThumborStorage(),\n height_field='photo_height',\n width_field='photo_width')\n photo_height = models.IntegerField(blank=True, null=True)\n photo_width = models.IntegerField(blank=True, null=True)\n\nIn the code\n'''''''''''\n\nYou can get the Thumbor ``uuid`` from the ``<ImageField>`` instance using:\n\n.. code-block:: python\n\n my_stuff.photo.storage.key(my_stuff.photo.name)\n\nThis is useful to ``generate_url()`` with Django-thumbor_ when original files are stored on Thumbor. Thus,\nyou can pass the key as url parameter.\n\nCHANGELOG\n=========\n\n2.0.0\n'''''\n\n* Add support for Django 3.2.\n\nPossible breaking change\n------------------------\n\nThe leading ``/`` in the path of the file stored in the database has been removed\ndue to a breaking change introduced un Django 3.2.11.\n\nhttps://docs.djangoproject.com/en/4.0/releases/3.2.11/#cve-2021-45452-potential-directory-traversal-via-storage-save\n\nThat release handle seamlessly both pre-2.0.0 style (*/image/...*) and\npost-2.0.0 style paths (*image/...*) so there is not need to migrate your database\nto replace */image/...* with *image/...*.\n\n\n1.13.0\n''''''\n\n* Drop support for Django < 2.1 and Python 2.7, 3.4 and 3.5\n* Use GitHub actions for CI instead of Travis.\n\n\n1.11.0\n''''''\n\n* Drop support for Django < 1.11 and Python 3.4.\n* Remove ``mock`` from dependencies.\n\n\n0.92.2\n''''''\n\n* Fix ``readonly_to_rw_url()`` to manage suffix in the urls.\n\n0.92.1\n''''''\n\n* Handle status code of the Thumbor server response when posting an image.\n\n0.92.0\n''''''\n\n* Added experimental Python 3.4 support (Thanks to *Charlie 123*.)\n* Fixed broken support for Django < 1.7 (Thanks to *Rizziepit*.)\n* Added unicode support in file names (Thanks to *Rizziepit*.)\n\n0.91.6\n''''''\n\n* Add ``storages.readonly_to_rw_url()``, a function to convert a read-only thumbor url in a rw url.\n\n0.91.5\n''''''\n\n* Use THUMBOR_SERVER to generate the original file url.\n\nBackward imcompatibilities\n--------------------------\n\n* ``THUMBOR_SERVER`` and ``THUMBOR_SECURITY_KEY`` are required in settings.\n\n0.91.4\n''''''\n\n* Add ``ThumborStorage.key(name)`` to retrieve the Thumbor uuid from the name.\n\n0.91.3\n''''''\n\nBackward imcompatibilities\n--------------------------\n\n* ``THUMBOR_WRITABLE_SERVER`` setting is replaced by ``THUMBOR_RW_SERVER`` since it is now used to retrieve the\n original file.\n\nTODO\n====\n\n* PUT\n\n.. _Requests: http://www.python-requests.org/en/latest/\n.. _Thumbor: https://github.com/globocom/thumbor\n.. _Libthumbor: https://github.com/heynemann/libthumbor\n.. _Django-thumbor: https://django-thumbor.readthedocs.org/en/latest/\n\n\n",
"bugtrack_url": null,
"license": "MIT Licence",
"summary": "Django custom storage for Thumbor backend.",
"version": "2.0.0",
"project_urls": {
"Homepage": "https://github.com/Starou/django-thumborstorage",
"Issue Tracker": "https://github.com/Starou/django-thumborstorage/issues",
"Source Code": "https://github.com/Starou/django-thumborstorage"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8b6b8f1af83872c03cbd8fbb03f728c7a9b6e0ea1878a6877dca715749cc1d49",
"md5": "8c19fe4dc54c8d1e54acfbbe9d279c92",
"sha256": "7a10ad19e4a15424167ccf6cd40787a3a63f2e5ae469d15e605d5a753a791841"
},
"downloads": -1,
"filename": "django-thumborstorage-2.0.0.tar.gz",
"has_sig": false,
"md5_digest": "8c19fe4dc54c8d1e54acfbbe9d279c92",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 122469,
"upload_time": "2022-04-07T12:29:59",
"upload_time_iso_8601": "2022-04-07T12:29:59.207003Z",
"url": "https://files.pythonhosted.org/packages/8b/6b/8f1af83872c03cbd8fbb03f728c7a9b6e0ea1878a6877dca715749cc1d49/django-thumborstorage-2.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-04-07 12:29:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Starou",
"github_project": "django-thumborstorage",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "django-thumborstorage"
}