django-storages + sorl_thumbnail + S3 not working well together (URLs mismatch)
I was able to make it work by defining MediaRootS3BotoStorage and StaticRootS3BotoStorage as follows:
from storages.backends.s3boto import S3BotoStorage
from django.conf import settings
class StaticRootS3BotoStorage(S3BotoStorage):
"""
Storage for static files.
"""
def __init__(self, *args, **kwargs):
kwargs['location'] = 'static'
super(StaticRootS3BotoStorage, self).__init__(*args, **kwargs)
class MediaRootS3BotoStorage(S3BotoStorage):
"""
Storage for uploaded media files.
"""
def __init__(self, *args, **kwargs):
kwargs['location'] = 'media'
super(MediaRootS3BotoStorage, self).__init__(*args, **kwargs)
This link can be helpful https://github.com/jamstooks/django-s3-folder-storage
I had the same problem and the solution by Salma Hamed turned out to be the right one for me.
Before we had
StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static')
MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media')
which resulted in the wrong 'storage' values in our thumbnail_kvstore table. This lambda definition does not create a new class and thus type(StaticRootS3BotoStorage()) returns 'storages.backends.s3boto.S3BotoStorage', which is written into the table. Because these 'storage' values are used to instantiate later the storage in order to get the image URLs when displaying, this resulted in S3BotoStorage() to be used for this. So the 'location' argument was lost.
The solution by Salma Hamed that defines these custom storages as classes fixes this.
Thanks for that!
Have you tried setting THUMBNAIL_PREFIX to media/cache/?
http://sorl-thumbnail.readthedocs.org/en/latest/reference/settings.html#thumbnail-prefix