I am using django-storages and sorl_thumbnail together and I am using Amazon S3 for static and media files. I am using one bucket with 2 folders, 1 for static and 1 for media.
Here is my config:
MEDIA_ROOT = '/media/'
MEDIA_URL = 'https://s3.amazonaws.com/my-bucket/media/'
STATIC_ROOT = '/static/'
STATIC_URL = 'https://s3.amazonaws.com/my-bucket/static/'
AWS_STORAGE_BUCKET_NAME = 'my-bucket'
DEFAULT_FILE_STORAGE = 'my_lib.s3utils.MediaRootS3BotoStorage'
STATICFILES_STORAGE = 'my_lib.s3utils.StaticRootS3BotoStorage'
MediaRootS3BotoStorage
and StaticRootS3BotoStorage
are defined like this:
StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static')
MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media')
When I am using sorl_thumbnail, the thumbnails generated are located in the right directory: https://s3.amazonaws.com/my-bucket/media/cache
but when sorl_thumbnail is trying to retrieve an already existing thumbnail, the URL generated is: https://s3.amazonaws.com/my-bucket/cache
, you will notice that the media
folder is omitted.
Do you have any idea how I could fix that?
I know I could just use django-storages and have my static and media files all mixed up in my bucket, but that's a bit too dirty for my taste :)
Thank you!
super()
methods on each of the__init__()
methods above are calling the wrong classes. They should be:super(StaticRootS3BotoStorage, self).__init__(*args, **kwargs)
andsuper(MediaRootS3BotoStorage, self).__init__(*args, **kwargs)
– Gory