Support sending bytes/stream as photos (improved _get_extension)

Letting _get_extension work for photos even when the only information
available is a stream or a few bytes allows sending arbitrary bytes
as photos, if force_document was not set to True explicitly.
This commit is contained in:
Lonami Exo
2019-02-12 11:33:06 +01:00
parent 8f8ae9aee5
commit bf11bbd8a6
2 changed files with 15 additions and 1 deletions

View File

@@ -337,6 +337,12 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
else:
file_name = str(file_id)
# If the file name lacks extension, add it if possible.
# Else Telegram complains with `PHOTO_EXT_INVALID_ERROR`
# even if the uploaded image is indeed a photo.
if not os.path.splitext(file_name)[-1]:
file_name += utils._get_extension(file)
# Determine whether the file is too big (over 10MB) or not
# Telegram does make a distinction between smaller or larger files
is_large = file_size > 10 * 1024 * 1024