I have the following code to download media from chat:
getmessage = client.get_messages(dialog, limit=1000)
for message in getmessage:
try:
if message.media == None:
print("message")
continue
else:
print("Media**********")
client.download_media(message)
I want to limit the download media size to X MB,
How can I get the media size in bytes before I download it?
2
Answers
You can get the file size with this telegram bot api: https://core.telegram.org/bots/api#file
You should send file_id as parametr, you can find file_id inside your message object.
You can refer to the Objects Reference for
Message
to find out themessage.file
property. It will be aFile
object with asize
property. Thus:Note that
file
will beNone
for media like polls.