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

# Files

> Upload and download files during a test.

Momentic can upload files into native file pickers and capture files that the
page downloads. Both work through dedicated step options rather than a separate
step type.

## File upload

Use the **File upload** step to hand a file to the next native file picker that
opens on the page.

<Warning>
  The step installs a listener on the next file picker. It must run **before**
  the picker is triggered, otherwise nothing is uploaded.
</Warning>

```yaml theme={null}
steps:
  - fileUpload:
      path: https://raw.githubusercontent.com/momentic-ai/momentic/main/README.md
      name: notes.md # optional: rename the file as presented to the page
  - click: The "Choose file" button # opens the picker the upload feeds
```

### Setup

1. Add a **File upload** step with a source (see [Sources](#sources) below). The
   scalar form `fileUpload: <path>` works when you don't need to rename.
2. (Optional) Set `name` (**File name**) to rename the file as it's presented to
   the page. Defaults to the name in the URL or local path.
3. Add a **Click** step on the button or element that opens the picker.

### Sources

<ParamField path="Remote URL" type="http:// or https://">
  Any publicly accessible direct file URL. Must resolve to the file itself, not
  an HTML wrapper or redirect.

  ```
  https://raw.githubusercontent.com/momentic-ai/momentic/main/README.md
  ```
</ParamField>

<ParamField path="Previously downloaded file" type="file://<key>">
  Reference a file captured by an earlier [download
  step](#file-download) via its saved environment variable.

  ```
  file://{{ env.DOWNLOADED_FILE }}
  ```
</ParamField>

<ParamField path="Local file" type="path">
  Absolute path, or path relative to `momentic.config.yaml`. **CLI only.**
</ParamField>

### Limits

* One file per step.
* Max file size: 50 MB.

## File download

Momentic captures a download by attaching to the **Click** step that triggers
it, rather than a separate step type.

```yaml theme={null}
steps:
  - click:
      on: The "Export CSV" button
      waitForDownload: true # wait for the download to finish before moving on
      saveAs: DOWNLOADED_FILE # capture the file URL for later steps
```

### Setup

1. Add a **Click** step on the button or link that triggers the download.
2. Set `waitForDownload: true` (**Wait for download**) on that step. Momentic
   waits for the download to complete before moving on.
3. (Optional) Set `saveAs` (**Save to environment variable**, e.g.
   `DOWNLOADED_FILE`) to capture the resulting file URL. Later steps can
   reference it, including a [File upload](#file-upload) step via
   `file://{{ env.DOWNLOADED_FILE }}`.

### Limits

* One file per **Click** step.
* Download timeout: 10 seconds.
* Max file size: 50 MB.
* Downloaded files are deleted at the end of the session, or after 15 minutes,
  whichever comes first.
* Direct file inspection (reading contents, checking format, verifying the
  filename) is not supported.

## Round-trip: download then upload

A common pattern is downloading a file from one part of the app and uploading it
somewhere else in the same test.

1. **Click** (download button) with **Wait for download** on and **Save to
   environment variable** set to `DOWNLOADED_FILE`.
2. **File upload** with source `file://{{ env.DOWNLOADED_FILE }}`.
3. **Click** (the button that opens the next file picker).
