Telegram bot weird error : Bad Request: wrong file identifier/HTTP URL specified
Asked Answered
W

11

27

I am sending message to telegram channel using bot.

With using webhook method.

I'm sending file_id via the link. I got the file_id from a channel post.

For some files like GIF & video format (MP4),

when i use this code:

$url = 'https://api.telegram.org/bot'.token.'/sendVideo?chat_id='.uid."&video=".$file."&caption="
.urlencode($caption);

file_get_contents($url);

i get such this error :

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

I really don't know why i get this, It's like this is random for errors, Because the code is depended to nothing i guess.

I use file_id that i've got from a channel's post.

What is the reason of that error? Bad Request: wrong file identifier/HTTP URL specified

  • I've searched all related topics, I've found NO good information .
Where answered 9/3, 2017 at 14:19 Comment(1)
How did you get the file_id? Through the same bot with which you are trying to send the video?Skirting
S
21

There are many possible reasons for this as mentioned in the documentation:

  • It is not possible to change the file type when resending by file_id. i.e. a video can't be sent as a photo, a photo can't be sent as a document, etc.
  • It is not possible to resend thumbnails.
  • Resending a photo by file_id will send all of its sizes.
  • file_id is unique for each individual bot and can't be transferred from one bot to another.
Skirting answered 9/3, 2017 at 16:20 Comment(1)
you sir, are a lifesavorHanukkah
B
13

Your Awnser is here @farzad

Sending by file_id

  • file_id is unique for each individual bot and can't be transferred from one bot to another.
Bonus answered 19/4, 2017 at 10:45 Comment(2)
Must use my own bot file_id!Gump
I totally missed that in the docs, was going crazy.. thank you!Airdrome
P
12

Go to @webpagebot and send him an URL to the file. The telegram's cache will be invalidated, and this should work. Seems that it is a bug on the server.

In my case I couldn't upload an image (as sticker), http://.../blabla.webp not via telegram app, not via telegram bot API.

Patriotism answered 23/5, 2018 at 20:20 Comment(2)
this resolved the issue, thank you. Was the bug ever raised with TG? Doesn't seem so: bugs.telegram.org/?sort=rate&query=webpagebotPastorale
This is correct with my case. I've tried with some normal png, jpeg and it works!Currant
D
4

Got the same error, it happens because:

  • Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.

Source: https://core.telegram.org/bots/api#sendvideo

Just try to post another video with file size <= 50 MB.

Demigod answered 5/7, 2021 at 18:46 Comment(0)
O
3

if your url not seen from telegram server or your url is incorrect this error has been seen.

also you can send data to this url with multipart html post method(please fill {YourBotToken} and {your_channel_name_with_Atsign} value):

<form action="https://api.telegram.org/bot{YourBotToken}/sendVideo" method="POST" enctype="application/x-www-form-urlencoded">
<input type="file" name="video" />
<input type="hidden" name="chat_id" value="{your_channel_name_with_Atsign}" />
<button type="submit" >send</button>
</form>

in c# sample code is:

 public bool sendVideo(string filename,string sendTo)
        {
            try
            {
                var botToken="{YourBotToken}";
                var sendTo="{your_channel_name_with_Atsign}";
                var filePath = "C:\\sample\\" + filename;

                var sendTo, ="@YourChannelNameWithAtSign";
                var bytesOfFile = System.IO.File.ReadAllBytes(filePath);
                var url = $"https://api.telegram.org/bot{botToken}/sendVideo";
                var res =Upload(url, sendTo, "video", bytesOfFile, filename).Result;

            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }



        private static async Task<string> Upload(string actionUrl,string chat_id,string fileParamName, byte[] paramFileStream, string filename)
        {
            var formContent = new MultipartFormDataContent
            {
                {new StringContent(chat_id),"chat_id"},
                {new StreamContent(new MemoryStream(paramFileStream)),fileParamName,filename}
            };
            var myHttpClient = new HttpClient();
            var response = await myHttpClient.PostAsync(actionUrl.ToString(), formContent);
            string stringContent = await response.Content.ReadAsStringAsync();

            return stringContent;
        }

this way does not need to have a website and you can use that from your stand alone system.

Occlude answered 9/3, 2020 at 15:42 Comment(0)
C
2

If you forward a file (photo, audio, ...) to a bot, you will get a valid file_id for this file (for your bot). It should be safe to use this id to send the file, but it seems it dosen't work for some files (audio, video, ...)!! (May be a Telegram API bug).

You can download and reupload the file to your bot, to get a new file_id and this id will work.

Colchester answered 27/3, 2017 at 17:42 Comment(1)
It appears if the file is too large they give you an id, but don't store it. Kind of annoying.Counseloratlaw
A
0

In my case, this error occurred because I tried sending an image twice (if the first time it didn't work, I'd reduce the size to under 5mb and send again). Apparently Telegram caches the previous request, so when a new request to send another image with the same name as the first one arrives, it just returns the previous error without attempting to send it.

To solve it, I gave the resized image a new name (used random + md5 to get a unique string).

Amatory answered 29/11, 2021 at 21:6 Comment(0)
M
0

In sendDocument, sending by URL will currently only work for GIF, PDF and ZIP files.

https://core.telegram.org/bots/api#sending-files

If you want to send video, only allow .MP4

Another file type, I used sendmessage (but with link inside text).

Morrow answered 12/6, 2022 at 9:22 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Anglia
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewKariekaril
N
0

Use the correct file format

  • When sending by URL the target file must have the correct MIME type (e.g., audio/mpeg for sendAudio, etc.).
  • In sendDocument, sending by URL will currently only work for GIF, PDF and ZIP files.
  • To use sendVoice, the file must have the type audio/ogg and be no more than 1MB in size. 1-20MB voice notes will be sent as files.
  • Other configurations may work but we can't guarantee that they will.

Source: https://core.telegram.org/bots/api#sending-files

Numbing answered 17/7 at 21:45 Comment(0)
R
-1

your mime type video is incorrect change it

Recountal answered 12/2, 2020 at 17:2 Comment(0)
L
-1

In my case, for some reason, the error came out when image url has extension full uppercase.

This does not work:

https://example.com/image.JPG

This works:

https://example.com/image.jpg
Linage answered 12/1, 2023 at 17:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.