Skip to content

Commit

Permalink
Fix uploading images by content
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeemakr committed May 14, 2020
1 parent 164473d commit 92494b5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions thr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
'''
Expand Down

0 comments on commit 92494b5

Please sign in to comment.