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

# File picker

> Let users pick one or several files with the native file dialog

[See the platform support matrix](https://filekit.mintlify.site/platform-support.md#filekit-dialogs)

`openFilePicker` shows the platform's native file dialog and returns the selected file as a `PlatformFile`, or a list of files in multiple mode.

## Usage

```kotlin Compose theme={null}
val launcher = rememberFilePickerLauncher(
    onError = { failure -> showError(failure.message) },
) { file ->
    // file is a PlatformFile, or null when the user cancelled
}

Button(onClick = { launcher.launch() }) {
    Text("Pick a file")
}
```

```kotlin Suspend API theme={null}
val file: PlatformFile? = FileKit.openFilePicker()
```

The result is `null` when the user cancels. Failures go to `onError` in Compose, or are thrown as a `FileKitDialogException` by the suspend API. See [Results and errors](https://filekit.mintlify.site/dialogs/error-handling.md).

## Try it

This is the FileKit sample running in your browser. Pick files, switch the selection mode or restrict extensions, then open a file to inspect its metadata.

[Open in a new tab ↗](https://vinceglb.github.io/FileKit/?demo=file-picker)

## Options

In Compose, pass these options to `rememberFilePickerLauncher`. `launch()` takes no arguments.

**type** `FileKitType` (default: File())

Which files the user can pick. `File()` allows any file.

**values**

**File(extensions)** `FileKitType`

Files with the given extensions, without the dot: `FileKitType.File("pdf", "docx")`. See [Filter by extension](#filter-by-extension).

**Image, Video, ImageAndVideo** `FileKitType`

Media files. Opens the native [gallery picker](https://filekit.mintlify.site/dialogs/gallery-picker.md) on Android and iOS, and a filtered file dialog elsewhere.

**mode** `FileKitMode` (default: Single)

How many files the user can pick. The result type follows the mode.

**values**

**Single** `PlatformFile?`

One file.

**Multiple(maxItems)** `List\<PlatformFile\>?`

Several files. `maxItems` is `1` to `50`, or `null` for no limit. See [Pick multiple files](#pick-multiple-files).

**SingleWithState, MultipleWithState(maxItems)** `FileKitPickerState`

Reports progress while picked files are prepared. The suspend API returns a `Flow`. See [Track progress](#track-progress).

**directory** `PlatformFile?` (default: null)

Folder the dialog opens in. Ignored on Android and the web.

**dialogSettings** `FileKitDialogSettings` (default: createDefault())

Title, parent window, and other [per-platform settings](https://filekit.mintlify.site/dialogs/dialog-settings.md).

## Filter by extension

Pass the extensions without the dot:

```kotlin Compose theme={null}
val launcher = rememberFilePickerLauncher(
    type = FileKitType.File("pdf", "docx"),
    onError = { failure -> showError(failure.message) },
) { file ->
    // a pdf or docx file, or null
}
```

```kotlin Suspend API theme={null}
val file = FileKit.openFilePicker(type = FileKitType.File("pdf", "docx"))
```

`FileKitType.File` also accepts a `List<String>` or a `Set<String>`.

## Pick multiple files

`FileKitMode.Multiple()` returns a `List<PlatformFile>`, or `null` when the user cancels:

```kotlin Compose theme={null}
val launcher = rememberFilePickerLauncher(
    mode = FileKitMode.Multiple(maxItems = 10),
    onError = { failure -> showError(failure.message) },
) { files ->
    // List<PlatformFile>? with at most 10 files
}
```

```kotlin Suspend API theme={null}
val files = FileKit.openFilePicker(mode = FileKitMode.Multiple(maxItems = 10))
```

The iOS gallery picker and the Android Photo Picker enforce `maxItems` in their UI. Other dialogs, including Android's document picker fallback, have no native limit, so FileKit keeps the first `maxItems` files in the order the platform returns them.

## Track progress

`SingleWithState` and `MultipleWithState` report each step as a `FileKitPickerState`, which lets you show a loading indicator while large files are prepared. In Compose, each state reaches `onResult`. The suspend API returns a `Flow`:

```kotlin theme={null}
FileKit.openFilePicker(mode = FileKitMode.MultipleWithState()).collect { state ->
    when (state) {
        is FileKitPickerState.Started -> showLoading(total = state.total)
        is FileKitPickerState.Progress -> updateLoading(state.processed.size, state.total)
        is FileKitPickerState.Completed -> showFiles(state.result)
        is FileKitPickerState.Failed -> showError(state.cause.message)
        FileKitPickerState.Cancelled -> hideLoading()
    }
}
```

Progress matters most for iOS gallery picks, where FileKit copies each item before returning it. Other dialogs deliver every state at once when they close. See [Results and errors](https://filekit.mintlify.site/dialogs/error-handling.md#state-tracking-picker-modes) for the full state contract.

## Platform notes

| Platform | Behavior |
| - | - |
| Android | Storage Access Framework document picker. Extensions are converted to MIME types: unknown extensions are dropped, and if none is known every file is allowed. |
| iOS | `UIDocumentPickerViewController`. Media types open `PHPickerViewController`. |
| macOS | `NSOpenPanel`. |
| JVM | `NSOpenPanel` on macOS, `IFileDialog` on Windows, and the XDG Desktop Portal on Linux, with an AWT/Swing fallback when no portal runs. |
| Linux native | XDG Desktop Portal only, with no fallback dialog. Dialog settings support the title only. See [Linux setup](https://filekit.mintlify.site/dialogs/setup.md#linux-setup). |
| Windows native | `IFileDialog`. Dialog settings support the title only. |
| Web | `<input type="file">`. The type filter becomes the `accept` attribute. `directory` and dialog settings are ignored. |

## Related

* [Gallery picker](https://filekit.mintlify.site/dialogs/gallery-picker.md) for photos and videos.
* [Reading files](https://filekit.mintlify.site/core/read-file.md) once the user has picked it.
* [Results and errors](https://filekit.mintlify.site/dialogs/error-handling.md) for cancellation and failure handling.


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