> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainlit.io/llms.txt
> Use this file to discover all available pages before exploring further.

# AskFileMessage

Ask the user to upload a file before continuing.
If the user does not answer in time (see timeout), a TimeoutError will be raised or None will be returned depending on raise\_on\_timeout.
If a project ID is configured, the messages will be uploaded to the cloud storage.

### Attributes

<ParamField path="content" type="str">
  Text displayed above the upload button.
</ParamField>

<ParamField path="accept" type="Union[List[str], Dict[str, List[str]]]">
  List of mime type to accept like `["text/csv", "application/pdf"]` or a dict like `{"text/plain": [".txt", ".py"]}`.
  More infos here [https://react-dropzone.org/#!/Accepting%20specific%20file%20types](https://react-dropzone.org/#!/Accepting%20specific%20file%20types).
</ParamField>

<ParamField path="max_size_mb" type="int" optional>
  Maximum file size in MB. Defaults to 2.
</ParamField>

<ParamField path="max_files" type="int" optional>
  Maximum number of files to upload. Defaults to 1. Maximum value is 10.
</ParamField>

<ParamField path="author" type="str" optional default="config.ui.name">
  The author of the message, defaults to the chatbot name defined in your
  config.
</ParamField>

<ParamField path="timeout" type="int" optional default={90}>
  The number of seconds to wait for an answer before raising a TimeoutError.
</ParamField>

<ParamField path="raise_on_timeout" type="bool" optional default={false}>
  Whether to raise a socketio TimeoutError if the user does not answer in time.
</ParamField>

### Returns

<ResponseField name="response" type="List[AskFileResponse] | None">
  The files uploaded by the user.
</ResponseField>

### Example

```python Ask for a text file theme={null}
import chainlit as cl


@cl.on_chat_start
async def start():
    files = None

    # Wait for the user to upload a file
    while files == None:
        files = await cl.AskFileMessage(
            content="Please upload a text file to begin!", accept=["text/plain"]
        ).send()

    text_file = files[0]

    with open(text_file.path, "r", encoding="utf-8") as f:
        text = f.read()

    # Let the user know that the system is ready
    await cl.Message(
        content=f"`{text_file.name}` uploaded, it contains {len(text)} characters!"
    ).send()

```

You can also pass a dict to the `accept` parameter to precise the file extension for each mime type:

```python Ask for a python file theme={null}
import chainlit as cl

file = await cl.AskFileMessage(
        content="Please upload a python file to begin!", accept={"text/plain": [".py"]}
      ).send()
```
