django-imagekit
django-imagekit copied to clipboard
Image not being processed and sent to Amazon s3
Hello. I'm having a problem and I really don't know how to solve it. I'm using imagekit 3.0.3 in Heroku, with Django and boto for S3.
I did some ImageSpecField in my localhost and everything went file, but when I put my project in Heroku it didn't work. But it appears the link to an image that wasn't uploaded to s3. Besides that, the original image is there.
Looking carefully, I noticed that in my localhost I get the MEDIA_ROOT before my path to the ImageSpecField, but in my heroku app the MEDIA_ROOT does not appear, and I really believe this is the problem why the image is not being uploaded.
Would you have some tips for me to solve this problem? Thanks in advance...
It's not likely to be your MEDIA_ROOT
since your S3 storage class probably doesn't use that setting.
Try using heroku run bash
to open up a shell and then start your Django shell with python manage.py shell
. From there you can get an instance of your model and execute instance.myspecfield.generate()
(where instance
is your model instance and myspecfield
is one of your ImageSpecFields. Please share whatever error you get there.
Actually it is returning any error. But it doesn't return anything at all.
But when I try to get instance.imagespecfield I get this error:
>>> pat4.logo_thumbnail
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/base.py", line 27, in __repr__
return "<%s: %s>" % (self.__class__.__name__, self or "None")
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py", line 129, in __nonzero__
existence_required.send(sender=self, file=self)
File "/app/.heroku/python/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 170, in send
response = receiver(signal=self, sender=sender, **named)
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/registry.py", line 50, in existence_required_receiver
self._receive(file, 'on_existence_required')
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/registry.py", line 58, in _receive
call_strategy_method(file, callback)
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/utils.py", line 132, in call_strategy_method
fn(file)
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/cachefiles/strategies.py", line 12, in on_existence_required
file.generate()
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py", line 92, in generate
self.cachefile_backend.generate(self, force)
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/cachefiles/backends.py", line 108, in generate
self.generate_now(file, force=force)
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/cachefiles/backends.py", line 96, in generate_now
file._generate()
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py", line 96, in _generate
content = generate(self.generator)
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/utils.py", line 115, in generate
content = generator.generate()
File "/app/.heroku/python/lib/python2.7/site-packages/imagekit/specs/__init__.py", line 158, in generate
options=self.options)
File "/app/.heroku/python/lib/python2.7/site-packages/pilkit/utils.py", line 301, in process_image
return img_to_fobj(img, format, autoconvert, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/pilkit/utils.py", line 16, in img_to_fobj
return save_image(img, StringIO(), format, options, autoconvert)
File "/app/.heroku/python/lib/python2.7/site-packages/pilkit/utils.py", line 166, in save_image
img.save(outfile, format, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/PIL/Image.py", line 1452, in save
save_handler(self, fp, filename)
File "/app/.heroku/python/lib/python2.7/site-packages/PIL/GifImagePlugin.py", line 258, in _save
fp.write(s)
TypeError: unicode argument expected, got 'str'
Besides that it does not return any error. The url appears on the site but it is not sent to S3
What version of PILKit is installed?
Version 1.0.0
And imagekit 3.0.3
What storage class are you using?
I am using django-sotrages with boto backend
django-storages*
Is this happening with all the images or just one? Also, could you share the version of PIL/Pillow you're using?
(Sorry a response has been so long in coming. I was moving but am settled now so hopefully I'll be able to figure this out soon.)
@henriquecf I'm using django-imagekit along with django-storages and boto, on Heroku, and everything is running fine. Here's my setup if you are interested:
s3utils.py:
from storages.backends.s3boto import S3BotoStorage
class StaticS3BotoStorage(S3BotoStorage):
"""
Storage for static files.
"""
def __init__(self, *args, **kwargs):
kwargs['location'] = 'static'
super(StaticS3BotoStorage, self).__init__(*args, **kwargs)
class MediaS3BotoStorage(S3BotoStorage):
"""
Storage for uploaded media files.
"""
def __init__(self, *args, **kwargs):
kwargs['location'] = 'media'
super(MediaS3BotoStorage, self).__init__(*args, **kwargs)
settings.py:
STATICFILES_STORAGE = 'myproject.s3utils.StaticS3BotoStorage'
DEFAULT_FILE_STORAGE = 'myproject.s3utils.MediaS3BotoStorage'
boto==2.9.4
django-storages==1.1.6
django-imagekit==3.0.3