Telegram bot has a file size limit for sending in 50MB.
I need to send large files. Is there any way around this?
I know about this project https://github.com/pwrtelegram/pwrtelegram but I couldn't make it work.
Maybe someone has already solved such a problem?
There is an option to implement the file upload via Telegram API and then send by file_id with bot.
I write a bot in Java using the library https://github.com/rubenlagus/TelegramBots
UPDATE
For solve this problem i use telegram api, that has limit on 1.5 GB for big files.
I prefer kotlogram - the perfect lib with good documentation https://github.com/badoualy/kotlogram
UPDATE 2
Example of something how i use this lib:
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)
}
private void sendToChannel(TelegramClient telegramClient, TLInputPeerChannel tlInputPeerChannel, String name, long fileId, int totalParts) {
try {
String mimeType = name.substring(name.indexOf(".") + 1);
TLVector<TLAbsDocumentAttribute> attributes = new TLVector<>();
attributes.add(new TLDocumentAttributeFilename(name));
TLInputFileBig inputFileBig = new TLInputFileBig(fileId, totalParts, name);
TLInputMediaUploadedDocument document = new TLInputMediaUploadedDocument(inputFileBig, mimeType, attributes, "", null);
TLAbsUpdates tlAbsUpdates = telegramClient.messagesSendMedia(false, false, false,
tlInputPeerChannel, null, document, getRandomId(), null);
} catch (Exception e) {
log.error("Error sending file by id into channel", e);
} finally {
telegramClient.close();
}
}
where TelegramClient telegramClient
and TLInputPeerChannel tlInputPeerChannel
you can create as write in documentation.
DON'T COPY-PASTE, rewrite on your needs.
There are a few different ways to do it. You can use a file splitter like HJSplit or 7-Zip. Or, you can use a file compression tool like WinRAR or WinZip to compress your files into smaller parts. Once you have split your files into multiple parts, you can send them through Telegram.
Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. See sendDocument official docs for a list of supported parameters and other info.
If you're sending bulk notifications to multiple users, the API will not allow more than 30 messages per second or so. Consider spreading out notifications over large intervals of 8—12 hours for best results. Also note that your bot will not be able to send more than 20 messages per minute to the same group.
With local Telegram Bot API server you are allowed to send InputStream with a 2000Mb file size limit, raised from 50Mb default.
IF you want to send file via telegram bot, you have three options:
So, I recommend you to store file_ids beforehand and send files by these ids (this is recommended by api docs too).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With