Add support for S3 storage for media

This commit is contained in:
Sander Steffann
2019-11-03 14:16:12 +03:00
parent 3775047aff
commit fb43e92865
3 changed files with 76 additions and 2 deletions

View File

@@ -750,11 +750,18 @@ class ImageAttachment(models.Model):
@property
def size(self):
"""
Wrapper around `image.size` to suppress an OSError in case the file is inaccessible.
Wrapper around `image.size` to suppress an OSError in case the file is inaccessible. When S3 storage is used
ClientError is suppressed instead.
"""
from django.conf import settings
if settings.MEDIA_STORAGE and settings.MEDIA_STORAGE['BACKEND'] == 'S3':
from botocore.exceptions import ClientError as AccessError
else:
AccessError = OSError
try:
return self.image.size
except OSError:
except AccessError:
return None