diff options
author | Will Hunt <will@half-shot.uk> | 2020-09-29 17:15:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-29 12:15:27 -0400 |
commit | c2bdf040aa93f3b542d1b0e2f6ce57853630ec6f (patch) | |
tree | 9f8dfca42da5a706238aae564c27206671bf5fa1 /synapse/rest/media | |
parent | Don't check whether a 3pid is allowed to register during password reset (#8414) (diff) | |
download | synapse-c2bdf040aa93f3b542d1b0e2f6ce57853630ec6f.tar.xz |
Discard an empty upload_name before persisting an uploaded file (#7905)
Diffstat (limited to 'synapse/rest/media')
-rw-r--r-- | synapse/rest/media/v1/media_repository.py | 7 | ||||
-rw-r--r-- | synapse/rest/media/v1/upload_resource.py | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py index 69f353d46f..ae6822d6e7 100644 --- a/synapse/rest/media/v1/media_repository.py +++ b/synapse/rest/media/v1/media_repository.py @@ -139,7 +139,7 @@ class MediaRepository: async def create_content( self, media_type: str, - upload_name: str, + upload_name: Optional[str], content: IO, content_length: int, auth_user: str, @@ -147,8 +147,8 @@ class MediaRepository: """Store uploaded content for a local user and return the mxc URL Args: - media_type: The content type of the file - upload_name: The name of the file + media_type: The content type of the file. + upload_name: The name of the file, if provided. content: A file like object that is the content to store content_length: The length of the content auth_user: The user_id of the uploader @@ -156,6 +156,7 @@ class MediaRepository: Returns: The mxc url of the stored content """ + media_id = random_string(24) file_info = FileInfo(server_name=None, file_id=media_id) diff --git a/synapse/rest/media/v1/upload_resource.py b/synapse/rest/media/v1/upload_resource.py index 3ebf7a68e6..d76f7389e1 100644 --- a/synapse/rest/media/v1/upload_resource.py +++ b/synapse/rest/media/v1/upload_resource.py @@ -63,6 +63,10 @@ class UploadResource(DirectServeJsonResource): msg="Invalid UTF-8 filename parameter: %r" % (upload_name), code=400 ) + # If the name is falsey (e.g. an empty byte string) ensure it is None. + else: + upload_name = None + headers = request.requestHeaders if headers.hasHeader(b"Content-Type"): |