Telegram bot api : issue with GIF upload/download size
Asked Answered
E

1

8

Faced with issue, when i am trying to send GIF to my bot, but bot can't access to original size of image. Seems like telegram servers converting it to mp4 (it is a good idea, looks fine) and when i trying to download it - it always looks like a thumbnail with maximum 320px of bigger side.

Looks, like it is an api bug, because for example here :

enter image description here

It describes as 600x473px, but real downloaded mp4 size is :

enter image description here

So, trying to understand - where i'm wrong here, as original gif size require for my project needs... Maybe any workaround exists here?

ps. in case of converting gif to mp4 manually with saving quality and size and then submitting to bot - it works awesome, without any additional compression and etc, but it is unacceptable to ask use do it before using bot.

update :

To reproduce (you need you bot/bot_token and also, be able to receive webhook with json) :

1) sending this gif (https://c2n.me/47Y3H37.gif) to the bot via windows 10 telegram client (v2.1.10). Using "send without compression". Gif size : 600x473, 3.35MB

2) Bot received and Telegram sending webhook :

{
  "update_id": 290360893,
  "message": {
    "message_id": 21,
    "from": {
      "id": 101483786,
      "is_bot": false,
      "first_name": "edited",
      "last_name": "edited",
      "username": "edited",
      "language_code": "en"
    },
    "chat": {
      "id": edited,
      "first_name": "edited",
      "last_name": "edited",
      "username": "edited",
      "type": "private"
    },
    "date": 1591962500,
    "animation": {
      "file_name": "9Ywn9p.gif.mp4",
      "mime_type": "video/mp4",
      "duration": 4,
      "width": 600,
      "height": 473,
      "thumb": {
        "file_id": "AAMCAgADGQEAAxVe42t2MTQQrFMyXbskwWiNkHjm3wACKwgAAtZ-GEtFrAh9bgzTOnpJm5QuAAMBAAdtAAMIgQACGgQ",
        "file_unique_id": "AQADekmblC4AAwiBAAI",
        "file_size": 15304,
        "width": 320,
        "height": 252
      },
      "file_id": "CgACAgIAAxkBAAMVXuNrdjE0EKxTMl27JMFojZB45t8AAisIAALWfhhLRawIfW4M0zoaBA",
      "file_unique_id": "AgADKwgAAtZ-GEs",
      "file_size": 68253
    },
    "document": {
      "file_name": "9Ywn9p.gif.mp4",
      "mime_type": "video/mp4",
      "thumb": {
        "file_id": "AAMCAgADGQEAAxVe42t2MTQQrFMyXbskwWiNkHjm3wACKwgAAtZ-GEtFrAh9bgzTOnpJm5QuAAMBAAdtAAMIgQACGgQ",
        "file_unique_id": "AQADekmblC4AAwiBAAI",
        "file_size": 15304,
        "width": 320,
        "height": 252
      },
      "file_id": "CgACAgIAAxkBAAMVXuNrdjE0EKxTMl27JMFojZB45t8AAisIAALWfhhLRawIfW4M0zoaBA",
      "file_unique_id": "AgADKwgAAtZ-GEs",
      "file_size": 68253
    }
  }
}

, so you can see there, that size is correct, but weight - no, it is only 68253 bytes = 66.65kb, instead of ~3.35MB (some less, because of converting)

3) Get File_id : CgACAgIAAxkBAAMVXuNrdjE0EKxTMl27JMFojZB45t8AAisIAALWfhhLRawIfW4M0zoaBA from this webhook and trying to use it in api by calling GET "https://api.telegram.org/bot{your_bot_token}/getFile?file_id=CgACAgIAAxkBAAMVXuNrdjE0EKxTMl27JMFojZB45t8AAisIAALWfhhLRawIfW4M0zoaBA" and you will receive :

{
  "ok": true,
  "result": {
    "file_id": "CgACAgIAAxkBAAMVXuNrdjE0EKxTMl27JMFojZB45t8AAisIAALWfhhLRawIfW4M0zoaBA",
    "file_unique_id": "AgADKwgAAtZ-GEs",
    "file_size": 68253,
    "file_path": "animations/file_12.mp4"
  }
}

4) Downloading file using this file_path : GET "https://api.telegram.org/file/bot{your_bot_token}/animations/file_12.mp4" and... getting this mp4 file : https://c2n.me/47Y4oAv.mp4 , with loss quality, weight and size (320x252)

But when you are trying to download it from Telegram client - by clicking "save as" - works fine, mp4 with appropriate size/weight. So seems like an api bug...

update#2 : tried to submit it via tfs telegram support, but also, can't login using my phone number... (https://c2n.me/47Yqswl.png). @pavel_durov, could you please fix it all :))

Empirical answered 8/6, 2020 at 8:42 Comment(4)
Just tried to reproduce: downloaded both with a right mouse click and after opening preview; Yes, Telegram indeed converts gif to mp4 but no issues with sizes so far, I have the original size (in my case, 500x500). Are you using Telegram API directly or via some framework? Maybe it is somehow relatedPrieto
@AntonZolotukhin directly, just re-producing GET calls via browser. So, when i getting the link to ready to download gif - it resized. Just re-checked. But you are right, Telegram providing high-res mp4 when you are trying to download it through the official client.Empirical
Just updated question with "how to reproduce". @AntonZolotukhinEmpirical
Having issue with photos too. I have provided high resolution (2k) file_id of the photo sending via bot api. In app, I receive only 1k resolution i.e. 1280. I don't know what I am missing.Epigastrium
P
3

It seems like the only workaround atm is to convert gif to mp4 (yeah, such a frustrating experience) until the issue is fixed.

Prieto answered 12/6, 2020 at 14:22 Comment(1)
unfortunately, converting before usage not an option :( Also, i found this issue, provided by you - before, you can see my comment there. Thanks for investigation anyway, AntonEmpirical

© 2022 - 2024 — McMap. All rights reserved.