> ## Documentation Index
> Fetch the complete documentation index at: https://n-a-818b4087.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Uploads and files

> Upload from paths, URLs, file IDs, memory, and open file objects.

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`.

```python theme={null}
telegram.send_photo(chat_id = 'YOUR_CHAT_ID', photo = 'https://example.com/photo.jpg')
telegram.send_photo(chat_id = 'YOUR_CHAT_ID', photo = message.photo.file_id)
telegram.send_photo(chat_id = 'YOUR_CHAT_ID', photo = '/path/to/photo.jpg')
```

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:

```python theme={null}
png_bytes = b'\x89PNG\r\n\x1a\n...'
telegram.send_photo(
    chat_id = 'YOUR_CHAT_ID',
    photo = png_bytes,
    file_name = 'chart.png'
)

zip_bytes = b'PK\x03\x04...'
telegram.send_document(
    chat_id = 'YOUR_CHAT_ID',
    document = zip_bytes,
    file_name = 'archive.zip'
)
```

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

```python theme={null}
with open('song.mp3', 'rb') as file:
    telegram.send_audio(
        chat_id = 'YOUR_CHAT_ID',
        audio = file,
        file_name = 'Song.mp3'
    )
```

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`:

```python theme={null}
with open('cover.jpg', 'rb') as cover:
    telegram.send_audio(
        chat_id = 'YOUR_CHAT_ID',
        audio = b'...',
        file_name = 'Song.mp3',
        thumbnail = cover,
        thumbnail_file_name = 'cover.jpg'
    )
```

Webhook certificates use `certificate_file_name` in the same way.

> [!TIP]
>
> 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.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.