From ccfd7a1015a5f525ddf97ef4f45a885a8d3cf93c Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 14 Mar 2020 12:12:40 +0100 Subject: [PATCH] Don't ignore thumb in send_file(input file) Fixes #1404 --- telethon/client/uploads.py | 19 +++++++++++-------- telethon/utils.py | 5 +++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index caf2dca4..3ec0990e 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -637,6 +637,14 @@ class UploadMethods: if as_image is None: as_image = utils.is_image(file) and not force_document + if as_image or not thumb: + # Images don't have thumb so don't bother uploading it + thumb = None + else: + if isinstance(thumb, pathlib.Path): + thumb = str(thumb.absolute()) + thumb = await self.upload_file(thumb) + # `aiofiles` do not base `io.IOBase` but do have `read`, so we # just check for the read attribute to see if it's file-like. if not isinstance(file, (str, bytes)) and not hasattr(file, 'read'): @@ -654,7 +662,8 @@ class UploadMethods: force_document=force_document, voice_note=voice_note, video_note=video_note, - supports_streaming=supports_streaming + supports_streaming=supports_streaming, + thumb=thumb, ), as_image) except TypeError: # Can't turn whatever was given into media @@ -699,17 +708,11 @@ class UploadMethods: supports_streaming=supports_streaming ) - input_kw = {} - if thumb: - if isinstance(thumb, pathlib.Path): - thumb = str(thumb.absolute()) - input_kw['thumb'] = await self.upload_file(thumb) - media = types.InputMediaUploadedDocument( file=file_handle, mime_type=mime_type, attributes=attributes, - **input_kw + thumb=thumb ) return file_handle, media, as_image diff --git a/telethon/utils.py b/telethon/utils.py index 0c63d143..b07cf875 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -427,7 +427,8 @@ def get_input_geo(geo): def get_input_media( media, *, is_photo=False, attributes=None, force_document=False, - voice_note=False, video_note=False, supports_streaming=False + voice_note=False, video_note=False, supports_streaming=False, + thumb=None, ): """ Similar to :meth:`get_input_peer`, but for media. @@ -481,7 +482,7 @@ def get_input_media( supports_streaming=supports_streaming ) return types.InputMediaUploadedDocument( - file=media, mime_type=mime, attributes=attrs) + file=media, mime_type=mime, attributes=attrs, thumb=thumb) if isinstance(media, types.MessageMediaGame): return types.InputMediaGame(id=types.InputGameID(