skip to Main Content

I want to send a simple jpg file ~30kb via telegram bot.
I have a camera that takes surveillance videos and creates thumbnails of them (Synology Surveillance Station).
These thumbnails are provided by the station at a specific URL like.

https://mystation.synology.me:5001/webapi/SurveillanceStation/Webhook/GetThumbnail/v1/<some-token>/thumbnail.jpg

When i open the URL in the browser a download of the thumbnail.jpg starts. (maybe thats already why it isn’t working)

So when i try to send a POST request with Postman

POST https://api.telegram.org/bot<token>/sendPhoto

Content-Type: application/x-www-form-urlencoded

chat_id: 123456789
photo: https://mystation.synology.me:5001/webapi/SurveillanceStation/Webhook/GetThumbnail/v1/<some-token>/thumbnail.jpg

then i get the error

{
    "ok": false,
    "error_code": 400,
    "description": "Bad Request: wrong file identifier/HTTP URL specified"
}

So can it be that it does not work because the URL starts a download? If I now take example images like https://telegram.org/img/t_logo.png it works fine. So it must have something to do with the URL.

Or is there another method that can do this?

2

Answers


  1. maybe thats already why it isn’t working

    Your right, Telegram expects an url that serves the image, not an uri that forces a download (probably using the Content-Disposition header)

    You should save the the image on your server, and then send them as a local file.

    Login or Signup to reply.
  2. Method 1: Upload the image file to Telegram using the multipart/form-data content type:

    1. Instead of providing the URL in the photo parameter, you can directly upload the image file using the multipart/form-data content type.
    2. In Postman, change the Content-Type header to multipart/form-data and remove the photo parameter from the request body.
    3. Add a new key-value pair in the body, where the key is photo and the value is the image file itself. Make sure to select the file in Postman for the value of the photo key.
    4. Send the modified POST request. This should upload the image file to Telegram and send it as a photo message.

    Method 2: Pre-upload the image to Telegram and use the file identifier:

    1. In this method, you can pre-upload the image to Telegram and obtain a file identifier for it.
    2. You can use the sendPhoto method with the multipart/form-data content type to upload the image file to Telegram and receive a file identifier in the response.
    3. Once you have the file identifier, you can send the photo using the sendPhoto method by providing the file identifier in the photo parameter, instead of the URL.
    4. This method requires two separate API calls, but it allows you to use the Telegram API to host the image for you.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search