如何将文件保存到电报服务器?

how to save file to telegram server?

我想使用 pytelegrambo 发送一个大视频文件,但它只有 50mb 的限制

当我阅读文档 https://core.telegram.org/bots/api/#sending-files 以将大文件发送到那里时,它说 如果文件已经存储在 Telegram 服务器的某处,则无需重新上传:每个文件对象都有一个 file_id 字段,只需将此 file_id 作为参数传递而不是上传。以这种方式发送的文件没有限制。

那么,如何将它保存在电报服务器上?

如果您想上传超过 API 的 documentation 中提到的限制的文件,您将有 2 个选择:

  1. 使用 MTPROTO API 客户端(Python 有 Telethon):

    await client.send_file(chat, zip_file, progress_callback=action.progress)
    # You're going to replace `chat`, `zip_file` and `action.progress` with your desired functions.
    
  2. 使用Local Bot API Server:

     git clone --recursive https://github.com/tdlib/telegram-bot-api.git
     cd telegram-bot-api
     mkdir build
     cd build
     cmake -DCMAKE_BUILD_TYPE=Release ..
     cmake --build . --target install
    

    然后你可以运行服务器使用:

     telegram-bot-api --api-id=API_ID --api-hash=API_HASH --local
    

    并让您的 BOT API 向 http://127.0.0.1:8081 发送请求或从中接收更新。

    您可以通过登录 here 并填写 API 开发工具表格来获取 API_ID 和 API_HASH。

    另外不要忘记在 运行 连接服务器时使用 --local,因为没有它你不能上传超过普通机器人限制的文件。