How to send large files from url to telegram?

I have large files (in formats MP4

and Zip

), and I want to send them to my chat with the Telegram bot, I used the following code:

file_get_contents('https://api.telegram.org/bot[[app:token]]/sendDocument?chat_id=24523586&document='.$fileAddress);

      

But it just can send small files, less than 50MB! But I know there is no file size limit for documents that are sent file_id

. You can see this page
Now, how can I do file_id

for my files? My files are uploaded to my server and I am using PHP.

+3


source to share


3 answers


The Telegram bot API can send files less than url

20MB using param, you should look for Send files .

If you want to send files of 20-50MB in size, you have to download and re-upload it to the Telegram bot API server.
You can link to this simple code



$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_URL => 'https://api.telegram.org/bot131210513:AXXXXXX/sendDocument?caption=Hello+World&chat_id=24523586',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: multipart/form-data'
    ],
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => [
        'document' => curl_file_create('/etc/hosts', 'plain/text', 'Hosts-file.txt')
    ]
]);
$data = curl_exec($curl);
curl_close($curl);

      

+3


source


You can install pwrtelegram on your server. Then just switch the API url and you can upload up to 1.5GB of files using your bot. This is the only possible way. See link for details.



Also, you cannot go through any random file_id

as Telegram won't send it. You can transfer the file_id file that was previously uploaded by your bot. To get around the limit, use the method above. It works really well.

+2


source


First, you must send your file to your bot and then receive the file.

After that, you can simply use fileID to send files, and that way the upload will be on the Telegram server, not yours. You can of course send files from your own server, but this method will reduce the speed for your bot.

Please note that when you send a file to your bot and get the fileID, from now on the file can be sent immediately without the need to store the files on your own server.

You don't need to do fileID.

All you need to do is send the file to the bot and let the bot know the fileID and save it somewhere in future transfers.

-1


source







All Articles