rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.78k stars 1.22k forks source link

[400] Bad Request: wrong file identifier/HTTP URL specified #1106

Closed yvasyliev closed 2 years ago

yvasyliev commented 2 years ago

Hi,

Could you please help me to understand why I can't send this video to telegram?

Link to video: https://v.redd.it/0w3soe17hve91/DASH_1080.mp4

My code

SendVideo sendVideo = SendVideo.builder()
        .chatId(String.valueOf(CHANNEL_ID))
        .video(new InputFile("https://v.redd.it/0w3soe17hve91/DASH_1080.mp4"))
        .caption("Some text")
        .build();

execute(sendVideo);

Stack trace

Error executing org.telegram.telegrambots.meta.api.methods.send.SendVideo query: [400] Bad Request: wrong file identifier/HTTP URL specified
    at org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod.deserializeResponseInternal(PartialBotApiMethod.java:53)
    at org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod.deserializeResponse(PartialBotApiMethod.java:33)
    at org.telegram.telegrambots.meta.api.methods.send.SendVideo.deserializeResponse(SendVideo.java:99)
    at org.telegram.telegrambots.bots.DefaultAbsSender.execute(DefaultAbsSender.java:314)
    at app.funclub.anadearmas.telegram.AnadeArmasFanbot.sendVideo(AnadeArmasFanbot.java:56)
    at app.funclub.anadearmas.Main.main(Main.java:89)

Dependency

<dependency>
    <groupId>org.telegram</groupId>
    <artifactId>telegrambots</artifactId>
    <version>6.1.0</version>
</dependency>
yvasyliev commented 2 years ago

UPDATE Solved by this W/A:

try (InputStream inputStream = new URL(videoUrl).openStream()) {
    String fileName = videoUrl.substring(videoUrl.lastIndexOf('/') + 1);
    SendVideo sendVideo = SendVideo.builder()
            .chatId(String.valueOf(CHANNEL_ID))
            .video(new InputFile(inputStream, fileName))
            .caption(text)
            .build();

    execute(sendVideo);
}