skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. You can refer to the Objects Reference for Message to find out the message.file property. It will be a File object with a size property. Thus:

    if message.media:
        print(message.file.size, 'in bytes')
    

    Note that file will be None for media like polls.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search