Skip to main content
Media parameters accept several source types. The library resolves them in a consistent order.

How strings are resolved

A string is handled in this order:
  1. An http:// or https:// URL is passed to Telegram as a URL.
  2. An existing filesystem path is opened and streamed to Telegram.
  3. A string that looks like a Telegram file_id is passed without uploading it again.
  4. Anything else raises FileNotFoundError.
For path uploads, the file’s base name is used unless you pass file_name. For URLs, Telegram uses the URL. For memory uploads, use file_name, file_names, thumbnail_file_name, or certificate_file_name.

Upload bytes from memory

bytes, bytearray, and memoryview are detected automatically:
When you do not provide a name, the library uses a sensible default for the endpoint (audio.mp3, video.mp4, photo.jpg, document.bin, and so on). For in-memory bytes, the content is also inspected, so a PNG upload becomes photo.png instead of photo.jpg.

Upload open file objects

The library never closes caller-owned file objects. You keep ownership and are responsible for closing them.

Backwards compatibility

byte = True is still accepted for backwards compatibility, but it does nothing now because bytes are detected automatically.

Thumbnails and extra files

Methods that support thumbnails accept the same source types as the main file. When a thumbnail comes from memory or an open file object, use thumbnail_file_name:
Webhook certificates use certificate_file_name in the same way.
Start with paths or URLs unless you already have bytes in memory. All uploads are streamed from disk, so large local files do not need to be loaded into RAM first.