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

# Download attachments

> Download Telegram files to disk or return them as bytes.

Use the `file_id` from a received message to download its attachment. The method writes to disk by default and returns the saved path.

```python theme={null}
message = telegram.send_document(
    chat_id = 'YOUR_CHAT_ID',
    document = '/path/to/report.pdf'
)

saved_path = telegram.download_attachment(
    file_id = message.document.file_id,
    file_name = 'downloaded-report.pdf',
    download_path = '/path/to/downloads/'
)

print(saved_path)
```

If `file_name` is omitted, the name from Telegram is used. If `download_path` is omitted, `telegram.current_directory` is used.

## Keep the file in memory

Set `as_bytes = True` to return the file contents instead of writing a file:

```python theme={null}
content = telegram.download_attachment(
    file_id = message.document.file_id,
    as_bytes = True
)
```

## Tune streaming and timeouts

Downloads are streamed in chunks. You can change the chunk size and override the client timeout for one download:

```python theme={null}
content = telegram.download_attachment(
    file_id = message.document.file_id,
    as_bytes = True,
    chunk_size = 128 * 1024,
    timeout = 60
)
```

Rate-limited (`429`) and server-error (`5xx`) responses are retried automatically, respecting the client's `max_flood_retries` setting. Timeouts raise `TelegramTimeoutError`; other network failures raise `TelegramNetworkError`.

## Change the default directory

`current_directory` is used whenever `download_path` is omitted. You can change it at any time:

```python theme={null}
telegram.current_directory = '/path/to/downloads/'
```

> [!NOTE]
>
> Disk downloads are written to a temporary `.part` file and moved into place only after the download completes.


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