From 92494b55dcb2531866cb4e9bca963f89c1e7949e Mon Sep 17 00:00:00 2001 From: coffeemakr Date: Thu, 14 May 2020 14:14:14 +0200 Subject: [PATCH] Fix uploading images by content --- thr/api.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/thr/api.py b/thr/api.py index c97b20f..9de7063 100644 --- a/thr/api.py +++ b/thr/api.py @@ -212,7 +212,9 @@ def send_text_message(self, recipient: str, content: str): message=message, recipient=recipient) - def upload_file(self, filename: Optional[Text] = None, content: Optional[bytes] = None, mimetype=None, key=None) -> FileMessage: + def upload_file(self, filename: Optional[Text] = None, + content: Optional[bytes] = None, + mimetype=None, key=None) -> FileMessage: ''' Upload a file and prepare a file message for it. @@ -231,13 +233,13 @@ def upload_file(self, filename: Optional[Text] = None, content: Optional[bytes] elif content is None: raise ValueError("Either content or filename has to be provided") - if mimetype is None: - mimetype, _ = mimetypes.guess_type( - filename) or 'application/octet-stream' + if mimetype is None and filename is not None: + mimetype, _ = mimetypes.guess_type(filename) or 'application/octet-stream' blob = self.upload_blob(data=content, key=key) - return FileMessage(blob_id=blob.id, key=blob.key, mime_type=mimetype, size=len(content), filename=filename) + return FileMessage(blob_id=blob.id, key=blob.key, mime_type=mimetype, + size=len(content), filename=filename) def upload_thumbnail(self, content: bytes, key) -> bytes: '''