How to send big files from URL to Telegram bot?

Ali YQB picture Ali YQB · Apr 6, 2017 · Viewed 14.5k times · Source

I have some big size files (in MP4 and Zip formats) and I want to send them to my chat by Telegram bot, I used the code below:

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

But it just can send files with small sizes, less than 50MB! But I know there is no file size limitation for documents which are sending by file_id. You can see this page
Now how can I make file_id for my files? My files are uploaded on my server and I am using PHP.

Answer

Sean picture Sean · Apr 9, 2017

Telegram bot API can only send files less than 20 MB by url param, you should lookup Sending Files section.

If you want to send 20-50 MB files, you should download and re-upload to Telegram bot API server.
You can refer 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);