Telegram bot 的发送文件大小限制为 50MB。我需要发送大文件。有没有办法解决?我知道这个项目https://github.com/pwrtelegram/pwrtelegram但我无法让它工作。也许有人已经解决了这样的问题?有一个选项可以通过 Telegram API 实现文件上传,然后通过file_id与 bot发送。我使用库https://github.com/rubenlagus/TelegramBots用 Java 编写了一个机器人更新为了解决这个问题,我使用了电报 api,它对大文件有 1.5 GB 的限制。我更喜欢 kotlogram - 具有良好文档的完美库https://github.com/badoualy/kotlogram更新 2我如何使用这个库的例子:private void uploadToServer(TelegramClient telegramClient, TLInputPeerChannel tlInputPeerChannel, Path pathToFile, int partSize) { File file = pathToFile.toFile(); long fileId = getRandomId(); int totalParts = Math.toIntExact(file.length() / partSize + 1); int filePart = 0; int offset = filePart * partSize; try (InputStream is = new FileInputStream(file)) { byte[] buffer = new byte[partSize]; int read; while ((read = is.read(buffer, offset, partSize)) != -1) { TLBytes bytes = new TLBytes(buffer, 0, read); TLBool tlBool = telegramClient.uploadSaveBigFilePart(fileId, filePart, totalParts, bytes); telegramClient.clearSentMessageList(); filePart++; } } catch (Exception e) { log.error("Error uploading file to server", e); } finally { telegramClient.close(); } sendToChannel(telegramClient, tlInputPeerChannel, "FILE_NAME.zip", fileId, totalParts)}这里TelegramClient telegramClient和TLInputPeerChannel tlInputPeerChannel您可以创建任意文件中写入。不要复制粘贴,根据您的需要重写。
添加回答
举报
0/150
提交
取消