DEV Community

Cover image for I built TgCloud: An open-source image hosting & CDN powered by Telegram storage (written in Go)
adrien
adrien

Posted on

I built TgCloud: An open-source image hosting & CDN powered by Telegram storage (written in Go)

Hi everyone! 👋

I'm a beginner developer, and over the last few weeks, I’ve been learning Go by building side projects. Like many of you, I love creating apps, but I absolutely hate getting AWS S3 bills or dealing with rate-limited public APIs just for basic image storage.

That led me to a simple, slightly crazy question:

Can Telegram be used as a reliable, zero-cost image hosting backend?

To find out, I built TgCloud.

Ideal for Small Projects (Not for Production!)

⚠️ Let's be clear from the start: This project is absolutely not intended to be used in production environments or for large commercial projects.

However, it is the perfect, lightweight, and free tool for:

  • Hosting images for your personal developer portfolio.
  • Powering your small side-projects or MVPs without putting down a credit card.
  • Storing your own desktop screenshots or mockups on a budget.

What is TgCloud?

TgCloud is a self-hosted, lightweight image hosting service and CDN wrapper written in Go. It allows you to upload images via an API, a remote URL, or a clean drag-and-drop web UI.

The magic part? It requires absolutely no database.

Quick Links


How It Works

The architecture is designed to be as stateless and lightweight as possible:

  1. Upload: You POST your image (file or remote URL) to the TgCloud binary.
  2. Stream & Store: TgCloud securely streams it to your private Telegram channel using the native Telegram Bot API.
  3. The ID: Telegram stores the file on its unlimited infrastructure and returns a unique, permanent File ID.
  4. Proxy & Serve: When someone requests https://your-vps.com/img/{id}, TgCloud fetches the raw data from Telegram's CDN and proxies it directly back to the user.

This makes it 100% hotlink-friendly and compatible with Discord, Slack, Markdown, or standard HTML <img> tags!


Features

  • Dual Upload: Supports local file upload (multipart/form-data) or remote URL cloning (application/json).
  • Instant Hotlinks: Generates direct, clean URLs that display images natively anywhere on the web.
  • Format Validation: Built-in protection that auto-rejects unsupported formats (supports JPEG, PNG, GIF, and WebP).
  • ShareX Integration: Comes with a custom .sxcu config so you can upload your desktop screenshots directly to your own server.

Quick Start (Deploy in 10 seconds)

TgCloud is compiled into a single pre-built binary, meaning you don't even need Go installed on your VPS to run it.

# 1. Clone the repo
git clone https://github.com.git
cd TgCloud

# 2. Create your environment file
echo "BOT_TOKEN=your_telegram_bot_token" > .env
echo "CHAT_ID=your_channel_id" >> .env
echo "PORT=8100" >> .env

# 3. Run it!
go mod tidy && go run main.go
Enter fullscreen mode Exit fullscreen mode

Your public image hosting server is now live at http://localhost:8100!


⚠ Limitations to Keep in Mind

Since this project leverages a chat platform API, it is intended for personal, hobby, and educational use:

  • Rate Limits: Telegram limits Bot API traffic to roughly ~30 requests per minute.
  • File Size: Maximum of 20MB per image (enforced by the Telegram Bot API).
  • Bandwidth: Since the tool proxies the image data, it uses your VPS bandwidth to serve the files, not Telegram's.

Looking for Feedback!

As I mentioned, I am still learning Go, so I would love to hear your thoughts on the code structure, error handling, or performance improvements.

  • Any tips on optimizing Go reverse proxies for heavy image streaming?

Check out the code on GitHub and let me know what you think in the comments below! 🦀


Made with ❤ by AdrienMttn

Top comments (0)