mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-07 20:42:32 +00:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user