【问题标题】:how to save file to telegram server?如何将文件保存到电报服务器?
【发布时间】:2022-01-11 19:38:44
【问题描述】:

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

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

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

【问题讨论】:

  • 将文件发送给机器人,它应该在相应的事件中收到file_id。

标签: python telegram-bot


【解决方案1】:

如果您想上传超过 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,因为没有它你不能上传超过普通机器人限制的文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-26
    • 2013-04-24
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 2010-09-14
    • 2011-08-12
    • 1970-01-01
    相关资源
    最近更新 更多