如何将大文件从URL发送到Telegram机器人? [英] How to send big files from URL to Telegram bot?
问题描述
我有一些大文件(MP4
和Zip
格式),我想通过Telegram bot将它们发送到我的聊天室,我使用下面的代码:
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);
但是它只能发送小于50MB的小文件!但是我知道通过file_id
发送的文档没有文件大小限制.您可以看到此页面
现在如何为文件创建file_id
?我的文件已上传到服务器上,并且正在使用PHP.
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.
推荐答案
Telegram机器人API只能通过url
参数发送小于20 MB的文件,您应该查找
Telegram bot API can only send files less than 20 MB by url
param, you should lookup Sending Files section.
如果要发送20-50 MB的文件,则应下载并重新上传到Telegram bot API服务器.
您可以参考这个简单的代码
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);
这篇关于如何将大文件从URL发送到Telegram机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!