问题
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.
回答1:
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);
回答2:
You can install pwrtelegram on your server. Then simply switch the API URL and you will be able to upload up to 1.5 GB of files with your bot. That is the only possible way. Check out the link for more information.
Also, you cannot pass in any random file_id
, as Telegram will not send it. You can only pass in a file_id which has been uploaded by your bot previously. To bypass the limit, use the method, above. It works very well.
回答3:
Firstly you should send your file(s) to your bot and then get the fileID.
After that you can just use the fileID to send your files and this way the load will be on Telegram's server not yours. Of course you can send the files from your own server to but this method will cause speed reduction for your bot.
Note that when you send a file to your bot and get the fileID, from that moment the file can be sent immediately without needing to store the files on your own server.
You don't need to make a fileID.
All you need is sending the file to the bot and let the bot find out the fileID and save it somewhere for future transfers.
来源:https://stackoverflow.com/questions/43256917/how-to-send-big-files-from-url-to-telegram-bot