# file_to_base64_message

> **Function** in `langchain_upstage`

📖 [View in docs](https://reference.langchain.com/python/langchain-upstage/utils/file_utils/file_to_base64_message)

Convert file to base64 encoded message format.

This is a generic utility function that can be used across different modules
for converting files to the format expected by Upstage APIs.

## Signature

```python
file_to_base64_message(
    file_path: str,
    supported_extensions: list[str],
    max_file_size_bytes: int,
    allow_urls: bool = True,
) -> dict
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `file_path` | `str` | Yes | Path to the file or URL to convert. |
| `supported_extensions` | `list[str]` | Yes | List of supported file extensions (e.g., ["pdf", "jpg"]). |
| `max_file_size_bytes` | `int` | Yes | Maximum file size in bytes. |
| `allow_urls` | `bool` | No | Whether to allow URLs. If True, URLs are returned as-is without validation. If False, URLs will raise ValueError. (default: `True`) |

## Returns

`dict`

Dictionary with 'type' and 'image_url' keys. For URLs, returns the URL
directly. For local files, returns base64 encoded data.

---

[View source on GitHub](https://github.com/langchain-ai/langchain-upstage/blob/1acdf18d9c969bb59ae0c5365f8b964e397f8b16/libs/upstage/langchain_upstage/utils/file_utils.py#L11)