Giter Site home page Giter Site logo

django-thumborstorage's People

Contributors

lcharlie123l avatar mojeto avatar rickydunlop avatar rizziepit avatar starou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-thumborstorage's Issues

response.status_code isn't checked when saving image into thumbor

Hi,
Response status code isn't checked after saving image file into thumbor server. ThumborStorageFile.write
Thumbor server can respond with several HTTP statuses thumbor doc

  • 201 Created (success)
  • 409 Conflict (image already exists)
  • 412 Precondition Failed (image is too small or the file is not an image)
  • 415 Unsupported Media Type (not documented, but can happen)

If upload wasn't successful code fails on exception
File "/usr/lib/python2.7/site-packages/django_thumborstorage/storages.py", line 102, in _save f.write(content=content) File "/usr/lib/python2.7/site-packages/django_thumborstorage/storages.py", line 46, in write self._location = unquote(response.headers["location"]) File "/usr/lib/python2.7/site-packages/requests/structures.py", line 54, in __getitem__ return self._store[key.lower()][1] KeyError: 'location'

Can we check response status and raise proper exception based on it?
e.g. 415 Unsupported Media Type can be ValidationError maybe

non-ascii characters in file name cause UnicodeEncodeError

I'm running into a UnicodeEncodeError when I try to save a file with non-ascii characters in the file name. A solution would be to utf-8 encode the name here. I'm using Django 1.6.10, Python 2.7 and django-thumborstorage 0.91.7. To reproduce:

from django.core.files.base import ContentFile
from django_thumborstorage.storages import ThumborStorage

storage = ThumborStorage()
storage.save(u'‘Ø', ContentFile(''))

I'm happy to implement a fix and open a PR.

Missing version 1.9.12

Some projects I work on are currently pinned to version 1.9.12, which appears to have vanished from PyPi, is this intentional? Is there a reason for this?

I've got a version of 1.9.12 installed locally, but when trying to install from TravisCI, I get this message:

Could not find a version that satisfies the requirement django-thumborstorage==1.9.12 (from -r requirements.txt (line 14)) (from versions: 0.91.1, 0.91.2, 0.91.3, 0.91.4, 0.91.5, 0.91.6, 0.91.7, 0.91.8, 0.92.0, 1.11.1)
No matching distribution found for django-thumborstorage==1.9.12 (from -r requirements.txt (line 14))

This version number looks very similar to 0.91.2, was there just a version numbering change?

ThumborStorageFile.close causes a new image download from thumbor server

Hi,
I found this issue when I optimised our production setup.
Configuration we use is django -> ThumborStorageFile -> Thumbor server -> S3 bucket (as image storage)

# django model
class Image(models.Model):
    checksum = models.CharField(max_length=40, unique=True, db_index=True)
    image = models.ImageField(
        upload_to='image/',
        storage=ThumborStorage(),
        height_field='height',
        width_field='width'
    )
    height = models.IntegerField(blank=True, null=True, db_index=True)
    width = models.IntegerField(blank=True, null=True, db_index=True)

Upload image workflow (save method):

  1. Image is uploaded to thumbor server in ThumborStorageFile.write method
  2. Image is downloaded from thumbor server because of ThumborStorageFile. _get_image_dimensions
  3. after getting image dimensions, the file is closed - here is a bug (more follow in code comments)
class ThumborStorageFile(ImageFile):

    file = property(_get_file, _set_file)

    def close(self):
        self._file = None  # pointer to file is removed
        super(ThumborStorageFile, self).close()  
        # parent method touch file property which will cause a new file download.

    # parent method from class File 
    def close(self):
         self.file.close()    
         # self.file goes to self._get_file which reads from self._file 
         # because self._file == None  _get_file starts a new download from thumbor server
         # the only method called on fresh downloaded image is .close()  :-(

source of django File

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.