Telegram Bot API: How to get MIME type of received photos
Asked Answered
L

1

6

How do I get the MIME type of photos that users send to my bot?

I am using the Telegram Bot API through Telegraf.

My bot is saving file id's from photos and videos that users are sending it and I want to be able to download the files later. The telegram API for the method getFile to download them states:

Note: This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received.

I am not entirely sure what this is supposed to mean. At no point I am receiving a File object so far and it does not even contain a MIME type. I assume they want to say that the MIME type (and file name) might get mixed up when downloading the actual file and you are therefore supposed to store it yourself.

When looking at the update types for different file types they usually contain the MIME type, as shown here: Video. Unfortunately, The update object for photos does not to contain this information: PhotoSize. Is there any other way to get the MIME type of photos?

Thanks for your help.

Leeland answered 8/1, 2020 at 19:55 Comment(0)
C
3

When we upload a images to Telegram, the file is either compressed or not. The compressed image will be a photo object, which in Telegram will always be a JPEG. Uncompressed image files, on the other hand, are referred to as a document/b> object which will have the mime-type of the original uploaded image. for example image/png.

Circe answered 20/11, 2020 at 10:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.