1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add support for S3 storage for media

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

View File

@@ -611,11 +611,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