26

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 .
Farzad
  • 842
  • 2
  • 9
  • 26

10 Answers10

19

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.
ManzoorWani
  • 1,016
  • 7
  • 14
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.

Saeed Heidarizarei
  • 8,406
  • 21
  • 60
  • 103
10

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.

xamgore
  • 1,723
  • 1
  • 15
  • 30
  • 1
    this resolved the issue, thank you. Was the bug ever raised with TG? Doesn't seem so: https://bugs.telegram.org/?sort=rate&query=webpagebot – FujiApple Jan 13 '22 at 02:06
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.

Ali Rasouli
  • 1,705
  • 18
  • 25
3

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.

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

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

Artem Shevtsov
  • 496
  • 5
  • 13
1

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 then 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.

Taha Jahangir
  • 4,774
  • 2
  • 42
  • 49
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).

Nickelza
  • 41
  • 1
  • 4
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).

  • 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](/help/how-to-answer). – Community Jun 13 '22 at 14:49
  • 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 Review](/review/late-answers/32000382) – Lajos Arpad Jun 14 '22 at 23:36
0

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
Mike V.
  • 37
  • 1
  • 6
-1

your mime type video is incorrect change it

mamal
  • 1,791
  • 20
  • 14