I am having a very strange error in using sorl thumbnails in my django project which uses S3 for media files. I have done my settings as pointed out in this answer https://stackoverflow.com/a/12848650/538191 and in fact all my other media files are being generated correctly.
But for the images generated through sorl thumbnails I am getting a url like this
https://he-s3.s3.amazonaws.com/cache/6f/cb/6fcb83175cb63f754fba9facec5dda7f.jpg?Signature=tgDEXyRV3gl3QtK%2BvwliqAtWqpM%3D&Expires=1357853609&AWSAccessKeyId=AKIAJLE6MUHDYS3HN6YQ
The problem is strange because its appending the S3 storage path to the image url, but its not adding /media/ in between. If you check
https://he-s3.s3.amazonaws.com/media/cache/6f/cb/6fcb83175cb63f754fba9facec5dda7f.jpg
the image actually exists there, but since the url is being generated wrong, I am getting a broken image. In the settings file I have declared the DEFAULT_FILE_STORAGE using s3boto and it contains
S3_URL = 'http://he-s3.s3-website-ap-southeast-1.amazonaws.com'
MEDIA_URL = S3_URL + '/media/'
I fail to understand why does the path in the sorl thumbnail image not contain media.
Any help is appreciated.
Update
Instead of being solved, the problem has in fact compounded. What I did was that I cleared the KVStore in thumbnail and all the database was cleared. I was happy because I thought the problem was solved, I was getting the correct url now. But then I refreshed the page, and again I was getting the wrong url. I don't understand what's happening, if I clear the thumbnail db, it shows the correct url once and after that it again shows the wrong url.
I'll bet that you're using something like this:
MediaS3BotoStorage = lambda: S3BotoStorage(location='media')
However this causes problems in sorl-thumbnail because it serializes the storage class into cache using the class name. Later when it deserializes, it instantiates as S3BotoStorage() without the location parameter. That's why it works the first time for you but then fails later.
You can fix it by using a full-fledged class instead of a factory:
class MediaS3BotoStorage(S3BotoStorage):
location = 'media'
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With