Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
VGSources
Blog

How to Self-Host a Telegram File-to-Link Bot on a VPS

Learn how to run a Telegram file-to-link proxy on a Linux VPS, keep your bot token private, stream files over HTTPS, and choose between Telegram’s hosted API and the official local Bot API server.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The reliable way to turn a Telegram file_id into a shareable download link is to run a small HTTPS service on your VPS. The service keeps the bot token private, calls Telegram’s getFile method, retrieves the temporary file_path, and streams the file to the person opening your link. Telegram’s hosted Bot API currently limits bot downloads to 20 MB, and each generated Telegram download URL is guaranteed to work for at least one hour, so your service must request a fresh path when needed.

This guide covers a hosted Bot API deployment, the official local Bot API server for more demanding workflows, HTTPS, Docker or Go deployment, security controls, and the failure cases that matter when you share links publicly.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a Telegram file-to-link bot actually does

A Telegram file link is not created by guessing a URL from the file_id. Your server has to perform a short exchange with Telegram every time it needs a downloadable path:

  1. Your bot receives a document, video, archive, or other file and records its file_id.
  2. A client requests your public endpoint, usually with the file_id in the path.
  3. Your VPS sends an authenticated getFile request to Telegram.
  4. Telegram returns metadata, including file_path.
  5. Your VPS fetches https://api.telegram.org/file/bot<token>/<file_path> and streams the response to the client.

The client sees your HTTPS address, not the Telegram bot-token URL. This is the core promise of the open-source telegram-file-proxy project: it “allows you to provide users with links to files by file_id without exposing the bot’s token.”

#1 Best Overall
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
  • Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized

A proxy does not make Telegram files permanent, and it does not remove Telegram’s download rules. It is an access layer that hides credentials, presents a stable URL, and lets you apply your own authentication, rate limits, headers, and logging.

Hosted Bot API limits you must design around

Download size

Telegram’s current hosted Bot API documentation says bots can download files up to 20 MB with getFile. Telegram’s FAQ repeats that limit. A hosted proxy therefore cannot reliably retrieve a 50 MB game patch or video simply by adding more VPS storage; the request fails at the Bot API layer. For larger-file or local-filesystem workflows, evaluate the official local Bot API server described later.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Temporary download paths

Telegram guarantees that the generated file URL remains valid for at least one hour. Treat that as a minimum validity period, not a permanent cache lifetime. Do not store the complete token-bearing URL in a database and reuse it indefinitely. Store the file_id, call getFile when a download begins, and fetch the returned path immediately. If a cached path returns an authorization or not-found error, call getFile again and retry once.

File IDs are scoped to a bot

Telegram describes file_id values as persistent, but they are bot-specific and cannot be transferred between bots. A file ID captured by one bot will not become valid merely because another bot uses the same string. Keep the bot identity alongside your stored IDs, especially if you operate separate bots for a community, a game server, and an internal moderation tool.

Choose the deployment model

Characteristic Telegram hosted Bot API Official local Bot API server
Typical use Small proxy for files within the hosted download ceiling Workflows needing local filesystem paths or evaluation of larger-file handling
File returned by getFile A Telegram-hosted relative file_path that your VPS fetches The server can return an absolute local filesystem path after getFile
Storage Your VPS can remain effectively stateless while streaming Reserve persistent disk space and plan cleanup, monitoring, and backups
Credentials Bot token Bot token plus the api_id and api_hash required by the official server
HTTPS Put your proxy behind Caddy, Nginx, or another TLS reverse proxy The official server accepts HTTP requests, so a TLS-termination proxy is required for remote HTTPS
Maintenance Application updates, logs, bandwidth, and token protection All hosted-mode tasks plus disk capacity, filesystem permissions, cleanup, configuration backup, and local-server upgrades
Failure recovery Request a new file_path when a temporary path expires Recover the API service, mounted storage, and proxy before diagnosing Telegram responses

The local server is still Telegram software. It does not eliminate the need to protect credentials or guarantee unlimited downloads. Select it because its local-path and operational model fit your workload, not because it removes every Bot API constraint.

Prerequisites for a VPS deployment

  • A Telegram bot created with BotFather and its token stored as a server-side secret.
  • A Linux VPS with enough CPU, memory, disk, and outbound bandwidth for the expected downloads.
  • A DNS name pointing to the VPS, such as files.example.net.
  • Firewall rules allowing SSH for administration and TCP 80/443 for certificate issuance and HTTPS. Restrict every other port unless your design needs it.
  • A reverse proxy capable of obtaining and renewing a TLS certificate.
  • Docker Compose if you are using the project’s container deployment, or a Go toolchain if you are building its documented Go binary.

Do not put the token in a browser URL, a client-side JavaScript bundle, a public issue, or a shell command copied into a shared support channel. Prefer an environment secret or a root-readable secret file, and ensure application logs redact it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
  • Includes Raspberry Pi 5 16GB with 2.4Ghz 64-bit quad-core CPU (16GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized

Capture and verify a file ID

Send a test document to your bot. In the bot update received by your application, locate the document, video, audio, or other file object and save its file_id. The ID is the input to your proxy; a local filename, Telegram message ID, or chat ID is not a substitute.

You can verify the Bot API exchange from the VPS without exposing the token in the URL shown to users. Keep the token in an environment variable and URL-encode the ID:

export BOT_TOKEN='replace-this-in-your-secret-store'
export FILE_ID='paste-the-file-id-here'
curl --fail --silent --show-error --get 
  --data-urlencode "file_id=${FILE_ID}" 
  "https://api.telegram.org/bot${BOT_TOKEN}/getFile"

A successful JSON response contains a result object with a file_path. The path is relative to Telegram’s file endpoint. Fetch it only from the server, where the token remains private:

curl --fail --location 
  "https://api.telegram.org/file/bot${BOT_TOKEN}/${FILE_PATH}" 
  --output test-download.bin

Do not paste either command, its shell history, or verbose HTTP output into a public bug report. On a multi-user VPS, use a secret-management mechanism that prevents other accounts from reading the process environment or command history.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Deploy the proxy application

Container route

The telegram-file-proxy project documents Docker Compose deployment and a mode that works with a local Bot API server. Obtain the project source from its official repository, review the documented environment variables, and keep the compose file outside a public web directory. Start it with the project’s documented command, normally docker compose up -d, then inspect container logs for a successful bind address and Telegram configuration.

Do not assume an example compose file is production-ready. Check that:

Rank #3
RasTech Raspberry Pi 5 8GB Kit 64GB Edition with Active Cooler,27W GaN 5.1V5A USB-C Power Supply,Pi5 8GB Board,64GB Card Readers Kit,Pi 5 Case,Dual 4K Micro HD Out Cables and User Manual
  • Pi5 8GB Pack: RasTech Pi 5 8GB kit includes 1 x Pi5 8GB board ,1 x 64GB Card, 2 x Card Readers,1 x Active Cooler,1 x Case for Pi5, 2 x 4K Micro HD Out Cable,1 x GaN 27W 5A USB-C Power supply,1 x Screwdriver and 1 x instructions.
  • Pi5 8GB Board: The Pi5 board is equipped with a 64-bit quad-core Arm Cortex-A76 processor running at 2.4GHz and an 800MHz VideoCore VII GPU with support for OpenGL ES 3.1 and Vulkan 1.2, which delivers a significant increase in graphics performance. Dual HD Out 4Kp60 display outputs and a built-in dual 4-channel MIPI camera/display transceiver provide state-of-the-art camera support. The Pi 5 offers a 2-3 times increase in CPU performance compare to Pi4.
  • Important Graphics Features: Equipped with an 800MHz VideoCore VII GPU and providing better graphics performance, suitable for multimedia applications,gaming,and graphics intensive tasks.Provides 1 UART interface,1 card slot that supports high-speed operation, 2 USB. 3 0.5 ports that support synchronous 0Gbps operation,2 USB 2.0 port ports,2 4Kp60 display outputs that support HDR.Built-in dedicated dual 4-channel 1Gbps MIPI DSI/CSI connectors,triple the total bandwidth.
  • Cooling Kit for Pi 5: Compatible with Active Cooler for Raspberry Pi5, It can provide Pi 5 board with better cooling effect in using. The Case can accurately access usb-c power jack,Micro HD Out ports, usb ports, Ethernet jack, card slot, power button, 4-lane MIPI DSI/CSI connectors and so on, and it also supports installation of cooling fan.
  • 64GB Card Kit and GaN 27W USB-C Power Supply: With extra 64GB card to store more files and card readers for multiple medium, keep better performance for Raspberry Pi 5, 27W USB C Power Supply is Compatible with Pi5 8GB, offers a variety of output voltage options, including 5.1V at 5A, 9.0V at 3.0A, 12.0V at 2.25A, and 15.0V at 1.8A, providing for different device requirements.
  • The bot token is injected through an environment secret rather than hard-coded in YAML.
  • The container listens on an internal interface or private port, with the reverse proxy as the only public entry point.
  • Restart behavior is defined so a host reboot does not silently leave links unavailable.
  • Container logs do not print authorization headers, full Telegram URLs, or query strings containing secrets.
  • Persistent volumes are used only when your selected mode actually stores files locally.

Go binary route

The same project documents a Go build. Build the pinned version of the source, run the resulting binary under a dedicated unprivileged account, and manage it with your Linux service supervisor. Give that account only the configuration and filesystem permissions it needs. Bind the application to localhost or a private network address, then let the TLS reverse proxy forward requests to it.

Pinning a release or commit makes rollback possible. Keep the previous binary until the new one has passed a health check and a real test download. If an upgrade changes configuration names, update the service definition and secret store together rather than placing the token in a new command-line argument.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Expose a stable HTTPS link

Terminate TLS at Caddy, Nginx, or an equivalent reverse proxy. The public route should look like https://files.example.net/<file_id>, while the proxy application remains on a private port. Redirect plain HTTP to HTTPS and set a reasonable request-body limit; this service downloads files and normally does not need to accept large uploads.

The project documents optional query parameters for response presentation:

  • content-type can set an appropriate media type when Telegram’s metadata is insufficient.
  • filename can provide a download name for the browser.

Treat both values as untrusted input. Allow only a controlled MIME-type list, such as common image, video, archive, or application types used by your community. Sanitize filenames by removing path separators, control characters, and excessive length. Set Content-Disposition with a safe fallback name, and consider X-Content-Type-Options: nosniff so a browser does not reinterpret an uploaded file as active content.

URL-encode a file ID when constructing a link. If your router treats a slash, question mark, or percent sign specially, reject ambiguous encodings instead of trying to normalize them. A strict route prevents a malformed ID from becoming a path traversal or routing bypass.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Vilros Raspberry Pi 5 Starter Kit MAX – Official 8GB RAM Pi 5 Board, 128GB Preloaded Micro SD, Case, Power Supply & Cooling – Complete Plug-and-Play Kit for Beginners & Advanced Users
  • 𝗦𝗲𝗮𝗺𝗹𝗲𝘀𝘀 𝗦𝗲𝘁𝘂𝗽 𝘄𝗶𝘁𝗵 𝗣𝗿𝗲-𝗜𝗻𝘀𝘁𝗮𝗹𝗹𝗲𝗱 𝗢𝗦: Start creating right out of the box—our kit arrives with Raspberry Pi OS already on the microSD card, saving you time and effort from day one.
  • 𝗘𝘃𝗲𝗿𝘆𝘁𝗵𝗶𝗻𝗴 𝗬𝗼𝘂 𝗡𝗲𝗲𝗱, 𝗔𝗹𝗹 𝗶𝗻 𝗢𝗻𝗲 𝗕𝗼𝘅: From the case to the power supply and a generous microSD card, we’ve bundled every essential so you can skip the extra shopping and focus on building your dream project.
  • 𝗔𝗱𝘃𝗮𝗻𝗰𝗲𝗱 𝗖𝗼𝗼𝗹𝗶𝗻𝗴 𝗳𝗼𝗿 𝗣𝗲𝗮𝗸 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲: Enjoy smooth, reliable operation as our whisper-quiet fan and heat sinks work together to keep your Pi running cool—even during intensive tasks.
  • 𝗩𝗲𝗿𝘀𝗮𝘁𝗶𝗹𝗶𝘁𝘆 𝗳𝗼𝗿 𝗔𝗻𝘆 𝗣𝗿𝗼𝗷𝗲𝗰𝘁: Whether it’s coding lessons, retro gaming, smart home setups, or robotics experiments, our kit powers unlimited possibilities, letting you tailor your Pi adventure to your passion.
  • 𝗚𝗹𝗼𝗯𝗮𝗹𝗹𝘆 𝗧𝗿𝘂𝘀𝘁𝗲𝗱 𝗯𝘆 𝗘𝗻𝘁𝗵𝘂𝘀𝗶𝗮𝘀𝘁𝘀 & 𝗘𝗱𝘂𝗰𝗮𝘁𝗼𝗿𝘀: Join a worldwide community of hobbyists, teachers, and first-time makers who rely on Vilros for top-tier quality, comprehensive support, and ongoing inspiration.

Keep the token and the file endpoint private

Authentication and link lifetime

A public URL can be copied to a forum, indexed, or hammered by download clients. If files are private, put your own authentication in front of the proxy: an authenticated session, a signed application URL with an expiry, or a one-time download record. The Telegram URL generated behind the scenes should never be returned in an error message or redirect.

Application-level expiry is separate from Telegram’s minimum one-hour URL validity. You can make your links expire after five minutes even though the server requests a fresh Telegram path on each authorized request. Conversely, a long-lived application link does not make the underlying Telegram path permanent; your server must perform the refresh.

Rate limits and resource controls

Limit requests per IP, account, and file ID. Add concurrent-download limits and a maximum response duration so one popular game archive cannot consume every connection. Apply bandwidth quotas appropriate to your VPS plan. Return a clear 429 response when a limit is reached and log the event without recording the bot token.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Logging and monitoring

Record request time, status, response bytes, latency, a hashed or truncated file ID, and the authenticated principal if you have one. Avoid full query strings when they may contain filenames or access signatures. Monitor disk usage, memory, open connections, outbound bandwidth, certificate renewal, and the ratio of Telegram errors to successful downloads. Alert on repeated token failures, sudden request spikes, and a growing local cache.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a local Bot API server is appropriate

The official telegram-bot-api server from TDLib requires an api_id and api_hash. After getFile, it can provide an absolute local filesystem path, which changes the proxy from a pure streaming client into a service that reads local storage.

The official README states that the Bot API server accepts only HTTP requests, so remote HTTPS must be handled by a TLS-termination proxy. Keep that server on a private network; do not expose its HTTP listener directly to the internet.

Best Value
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
  • Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM)
  • Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
  • CanaKit Premium High-Gloss Raspberry Pi 4 Case with Integrated Fan Mount, CanaKit Low Noise Bearing System Fan
  • CanaKit 3.5A USB-C Raspberry Pi 4 Power Supply (US Plug) with Noise Filter, Set of Heat Sinks, Display Cable - 6 foot (Supports up to 4K60p)
  • CanaKit USB-C PiSwitch (On/Off Power Switch for Raspberry Pi 4)

Before choosing this route, plan the operational details:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Mount persistent storage with enough headroom for Telegram’s local files and temporary downloads.
  • Define retention and cleanup rules so old game videos, replay files, and archives do not fill the disk.
  • Back up configuration and credentials separately from disposable downloaded files.
  • Set filesystem ownership so only the Bot API process and proxy can read the files.
  • Test recovery after a reboot, a full-disk condition, a lost mount, and a proxy certificate failure.
  • Keep the local server and proxy on compatible versions and document how to roll back.

Use hosted mode when your files fit within 20 MB and you want the smallest operational footprint. Move to the local server when local paths, storage control, or a workload that cannot use the hosted download ceiling justifies the extra maintenance.

Troubleshoot the common failures

getFile returns an error

Check that the ID came from the same bot whose token is configured. An ID from another bot is invalid for this request. Confirm that the token has not been revoked and that the file is within the hosted 20 MB download limit. Log Telegram’s error code and description, but redact the token and any complete file URL.

The Telegram fetch worked once and now fails

The generated path may have expired. Call getFile again using the stored file_id, replace the cached path, and retry the fetch once. If repeated refreshes fail, test the bot token and network egress from the VPS.

The public link exposes credentials

Inspect redirects, error pages, access logs, reverse-proxy logs, analytics, and browser developer tools. The client should see only your HTTPS hostname. Remove any code that redirects to Telegram’s file URL, rotate the bot token if it was exposed, and invalidate old secrets before restoring service.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The download has the wrong name or opens in a browser

Supply a controlled content-type and sanitized filename. Use an attachment disposition for archives and other files that should download rather than render. Never trust a user-provided filename as a filesystem path.

The local deployment returns an inaccessible path

Verify that the path exists inside the same container or host namespace used by the proxy, that the mount is present after reboot, and that Unix permissions allow the proxy account to read it. A path visible to the Bot API container is not automatically visible to a separate proxy container unless both mount the same volume.

Links time out under load

Check VPS outbound bandwidth, CPU, memory, reverse-proxy connection limits, and Telegram response latency. Add concurrency limits before increasing the server size. If local storage is involved, inspect disk I/O and free space as well as network metrics.

Production checklist

  • Bot token, api_id, and api_hash are stored as secrets and absent from public logs.
  • DNS points to the correct VPS and HTTPS certificate renewal has been tested.
  • The proxy application and any local Bot API listener are private behind the TLS reverse proxy.
  • File IDs are validated, URL-encoded, and associated with the correct bot.
  • Telegram paths are refreshed through getFile instead of treated as permanent URLs.
  • Response MIME types and filenames come from an allowlist and sanitization step.
  • Authentication, expiring links, rate limits, concurrency limits, and bandwidth controls match the privacy of the files.
  • Logs omit tokens and full Telegram URLs while retaining enough information to diagnose failures.
  • Disk, bandwidth, certificate, error-rate, and service-health alerts are active.
  • A test file has been downloaded from a clean browser and with a command-line client, and token rotation and rollback procedures are documented.

Bottom line

A VPS-hosted proxy is the simplest way to share Telegram files without handing out your bot token: accept a bot-specific file_id, call getFile, fetch the temporary Telegram path, and stream it through your own HTTPS hostname. Respect the hosted 20 MB ceiling and one-hour minimum URL lifetime. Add authentication, expiring application links, safe headers, rate limits, and redacted logs before publishing links. Choose the official local Bot API server only when local paths or a larger operational design outweigh the extra credentials, storage, reverse-proxy, and recovery work.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$259.95
Bestseller No. 2
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
Includes Raspberry Pi 5 16GB with 2.4Ghz 64-bit quad-core CPU (16GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$419.99
Bestseller No. 5
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM); Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
$159.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.