skip to Main Content

I’m well aware this question seems like a possible duplicate (e.g., 1, 2, 3), but I couldn’t find a straight answer to my scenario anywhere.
The exact flow is as follows:

  1. The Bot receives a message with a photo from a user. It then extracts and stores the file_id of the highest-quality photo out of the message.photo array (the last array item).
  2. The bot fires a getFile(file_id) request using the stored file_id, which returns a single link (NOT an array) that points to a low-quality file (slightly bigger than a thumbnail).

To summarize:

  • Using the exact file_id with getFile() returns a link to a low-quality file.
  • Using the exact file_id with sendPhoto() will send a full-size photo.

On the chance I’m missing something here, can anyone confirm that that’s expected behavior? Thanks.

3

Answers


  1. file_id’s are different in the photo array. use file_id which has the biggest file_size and then you could get the high quality file by getFile method

    Login or Signup to reply.
  2. Base on image resolution, "photo" array contains different number file_id. Use ctx.message.photo.lenght - 1 to access the last file_id for best quality.

    Login or Signup to reply.
  3. the best quality in -1 index

        raw = message.photo[-1].file_id
        
        path =path+"/"+raw+".jpg"
    
        file_info = bot.get_file(raw)
        downloaded_file = bot.download_file(file_info.file_path)
        with open(path,'wb') as new_file:
            new_file.write(downloaded_file)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search