Description
Title:
Problem downloading files via /file/bot...
endpoint when using telegram-bot-api
with --local
mode
Description:
When running telegram-bot-api
with the --local
option, we are experiencing issues downloading files via the /file/bot<token>/<file_path>
endpoint. The API does not reliably serve files, even though the files are supposed to be saved and accessible locally in this mode.
Even if the ctx.message shows this:
Steps to Reproduce:
- Start
telegram-bot-api
with the--local
flag enabled. - Use the
getFile
method to obtain a validfile_path
for a file (e.g., after sending or receiving a document or photo). - Attempt to download the file using:
http://<your_host>:<port>/file/bot<token>/<file_path>
- The request fails in one of the following ways:
- 404 Not Found
- Unexpected error (e.g. 400, 429, or 5xx)
- Download hangs or is incomplete
Expected Behavior:
- The file should be served directly and reliably from the local storage by the API, as long as it is not deleted and the
file_path
is valid.
Actual Behavior:
- The file is not served as expected.
- In some cases, a 404 or other HTTP error is returned, even though
getFile
reports the file as available. - In other cases, the download does not start or does not complete.
- The problem occurs for different file types and sizes.
Additional Information:
- This issue occurs with the latest version of
telegram-bot-api
9.0 - The bot has all necessary permissions.
- We have verified that the file is within the allowed size limits.
- We have reviewed the relevant parts of the source code (
Client.cpp
,on_update_file
, etc.) but could not identify a workaround. - The problem appears unique to
--local
mode
Environment:
- OS: Ubuntu 24.04
- telegram-bot-api version: 9.0
- How you deploy: Native on Ubuntu server 24.04
Logs & Error Messages:
4][t 6][1748117244.843397140][HttpConnectionBase.cpp:102][!HttpInboundConnection] Can read from the connection
[ 4][t 6][1748117244.843448162][BufferedFd.h:206][!HttpInboundConnection] Flush read: +255B[total:255B]
[ 4][t 6][1748117244.843462944][HttpReader.cpp:567][!HttpInboundConnection] Process header [host=>lmdntech.co.il]
[ 4][t 6][1748117244.843465089][HttpReader.cpp:567][!HttpInboundConnection] Process header [x-real-ip=>77.127.107.166]
[ 4][t 6][1748117244.843466043][HttpReader.cpp:567][!HttpInboundConnection] Process header [x-forwarded-for=>77.127.107.166]
[ 4][t 6][1748117244.843469142][HttpReader.cpp:567][!HttpInboundConnection] Process header [user-agent=>curl/8.5.0]
[ 4][t 6][1748117244.843471288][HttpReader.cpp:567][!HttpInboundConnection] Process header [accept=>/]
[ 4][t 6][1748117244.843473911][HttpConnectionBase.cpp:144][!HttpInboundConnection] Send query to handler
[ 4][t 6][1748117244.843477010][HttpConnection.cpp:27][!HttpConnection] Handle GET:/file/bot7343651493:AAE3swTi7DZh2GSIvfZWK5b_OAUERbA4spo/7343651493:AAE3swTi7DZh2GSIvfZWK5b_OAUERbA4spo/documents/file_1:keep-alive
host=lmdntech.co.il
x-real-ip=77.127.107.166
x-forwarded-for=77.127.107.166
user-agent=curl/8.5.0
accept=/
BEGIN CONTENT
END CONTENT
[ 4][t 6][1748117244.843507051][HttpConnection.cpp:77][!HttpConnection] Response headers: HTTP/1.1 404 Not Found
Connection: keep-alive
Content-Type: application/json
Content-Length: 55
[ 4][t 6][1748117244.843509197][HttpConnection.cpp:83][!HttpConnection] Send result: {"ok":false,"error_code":404,"description":"Not Found"}
[ 4][t 6][1748117244.843514919][HttpConnectionBase.cpp:156][!HttpInboundConnection] Can write to the connection
[ 4][t 6][1748117244.843516111][BufferedFd.h:140][!HttpInboundConnection] Nothing to write to [fd:39]
[ 4][t 6][1748117244.843523263][HttpConnectionBase.cpp:156][!HttpInboundConnection] Can write to the connection
[ 4][t 6][1748117244.843615055][BufferedFd.h:215][!HttpInboundConnection] Flush write: +157B[left:0B]
[ 4][t 6][1748117244.843916177][HttpConnectionBase.cpp:102][!HttpInboundConnection] Can read from the connection
[ 4][t 6][1748117244.843935012][HttpConnectionBase.cpp:186][!HttpInboundConnection] Can close the connection
Sample Code to Reproduce:
import requests
file_url = "http://<your_host>:<port>/file/bot<token>/<file_path>"
r = requests.get(file_url)
print(r.status_code)
print(r.content)
Using:
Node.js 22.16
TypeScript 5.8
Grammy 1.36
Express 5.1
Telegram Bot API 9.0
I tried in both servers, and none of them is worked.
One server is from Israel physically, and second server is from Europe, germany