17👍
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
8👍
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!
- Django multi-table inheritance alternatives for basic data model pattern
- Django 1.7 upgrade error: AppRegistryNotReady: Models aren't loaded yet
- Django favicon.ico in development?
- Django 'str' object is not callable
1👍
Have you tried setting THUMBNAIL_PREFIX to media/cache/?
http://sorl-thumbnail.readthedocs.org/en/latest/reference/settings.html#thumbnail-prefix
1👍
I had this same exact problem but I figured out a way around it.
I set my DEFAULT_FILE_STORAGE
back to storages.backends.s3boto.S3BotoStorage
, that way, when it looked for cache/
it would not miss, and I could still upload all of my files to media/
, and python manage.py collectstatic
still works properly because I still have that set as StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static')
.
Hope this help you, because this problem was driving me crazy.
- Django app defaults?
- Django selenium LiveServerTestCase
- Django m2m form save " through " table
- Convert python datetime with timezone to string
0👍
Found that sorl-thumbnail
is returning the cached KV
image url
using STATIC_URL
(on the next request after the initial thumbnail is created). Appears MEDIA_URL
has no affect.
Not the best solution. Added a S3
routing rule.
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>cache/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>media/cache/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
- Login_required decorator in django
- Django annotate query set with a count on subquery
- Django: model object "has no attribute '_meta'" in class based view
0👍
IDK why but @SalmaHamed ‘s solution didn’t work for me (Maybe its because of change in the django version or something). Instead, I replaced: MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media')
with: class MediaRootS3BotoStorage(S3Boto3Storage): location = 'media'
- Saving profile with registration in Django-Registration
- Login_required decorator on ajax views to return 401 instead of 302
- How to limit number of records in Django Rest Framework reverse relations
- Blank option in required ChoiceField
- Admin inline with no ForeignKey relation