Skip to content

Storage backends

hypha.storage_backends

This app defines the storage classes that are used to store the private and public media in the application. When the app moves to an installable app, users will be able to implement their own storage backends with different providers e.g. Azure

Most private files are served through the webapp to allow users to share links to the file and the recipient is then authenticated through the app rather than with the original file url with auth string.

Please set the following settings in order to configure this: DEFAULT_FILE_STORAGE PRIVATE_FILE_STORAGE

PublicMediaStorage

Bases: S3Boto3Storage

bucket_name class-attribute instance-attribute

bucket_name = AWS_PUBLIC_BUCKET_NAME

custom_domain class-attribute instance-attribute

custom_domain = AWS_PUBLIC_CUSTOM_DOMAIN

file_overwrite class-attribute instance-attribute

file_overwrite = False

querystring_auth class-attribute instance-attribute

querystring_auth = False

url_protocol class-attribute instance-attribute

url_protocol = 'https:'

PrivateMediaStorage

Bases: S3Boto3Storage

bucket_name class-attribute instance-attribute

bucket_name = AWS_PRIVATE_BUCKET_NAME

bucket_acl class-attribute instance-attribute

bucket_acl = 'private'

custom_domain class-attribute instance-attribute

custom_domain = False

default_acl class-attribute instance-attribute

default_acl = 'private'

encryption class-attribute instance-attribute

encryption = True

file_overwrite class-attribute instance-attribute

file_overwrite = False

querystring_auth class-attribute instance-attribute

querystring_auth = True

url_protocol class-attribute instance-attribute

url_protocol = 'https:'

url

url(name, parameters=None, expire=None)
Source code in hypha/storage_backends.py
def url(self, name, parameters=None, expire=None):
    url = super().url(name, parameters, expire)

    if hasattr(settings, "AWS_PRIVATE_CUSTOM_DOMAIN"):
        # Django storage doesn't handle custom domains with auth strings
        custom_domain = settings.AWS_PRIVATE_CUSTOM_DOMAIN
        parts = list(parse.urlsplit(url))
        parts[1:3] = custom_domain, filepath_to_uri(name)
        return parse.urlunsplit(parts)

    return url