Why i get Wrong file identifier/HTTP URL specified error in telegram bot?

白昼怎懂夜的黑 提交于 2019-12-19 11:44:08

问题


I'm new in telegram bot and try to send photo to user with this code:

await Bot.SendPhotoAsync(update.Message.Chat.Id, "http://182.126.201.42/" + "iisstart" + ".png");


but when i try run that code,get this error:

Bad Request: Wrong file identifier/HTTP URL specified


How can i solve that problem?thanks.


回答1:


The problem can be originated from the following issues:

  • the image file extension is not allowed by the telegram.
  • file size is larger than that allowed by the telegram.

You can start with the former one.




回答2:


Accoding to example you can sendPhoto:

await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.UploadPhoto);

            const string file = @"<FilePath>";

            var fileName = file.Split('\\').Last();

            using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var fts = new FileToSend(fileName, fileStream);

                await Bot.SendPhotoAsync(message.Chat.Id, fts, "Nice Picture");
            }

Documentation: https://mrroundrobin.github.io/telegram.bot/html/M_Telegram_Bot_TelegramBotClient_SendPhotoAsync_3.htm



来源:https://stackoverflow.com/questions/42048991/why-i-get-wrong-file-identifier-http-url-specified-error-in-telegram-bot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!