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

> Let the user choose where to save a file, then write your data to it

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

Open the native save dialog. FileKit returns the location the user picked as a `PlatformFile`, and you write your data to it. The file saver is not available on the web, so call it from a non-web source set such as `nonWebMain` (see [shared source sets](https://filekit.mintlify.site/platform-support.md#use-platform-specific-apis-from-shared-code)).

## Usage

```kotlin Compose theme={null}
val scope = rememberCoroutineScope()
val launcher = rememberFileSaverLauncher(
    dialogSettings = FileKitDialogSettings.createDefault(),
    onError = { failure -> showError(failure.message) },
) { file ->
    // onError covers the dialog only: handle write errors (IOException) here
    scope.launch { file?.writeString("Hello FileKit!") }
}

Button(onClick = { launcher.launch(suggestedName = "notes", defaultExtension = "txt") }) {
    Text("Save")
}
```

```kotlin Suspend API theme={null}
val file = FileKit.openFileSaver(suggestedName = "notes", defaultExtension = "txt")
file?.writeString("Hello FileKit!")
```

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

## Options

**suggestedName** `String`

File name without the extension.

**defaultExtension** `String?` (default: null)

Extension without the dot, appended to `suggestedName`.

**allowedExtensions** `Set\<String\>?` (default: null)

Save types offered by the dialog, without dots. A hint, not a validation.

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

Initial folder. Ignored on Android.

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

Required by the Compose launcher. In a Compose Desktop `Window`, `WindowScope.rememberFileSaverLauncher` makes it optional and parents the dialog to the window. See [Dialog settings](https://filekit.mintlify.site/dialogs/dialog-settings.md).

## Offer several file types

Pass `allowedExtensions` to let the user pick a format. `defaultExtension` stays the preselected one:

```kotlin theme={null}
val file = FileKit.openFileSaver(
    suggestedName = "report",
    defaultExtension = "pdf",
    allowedExtensions = setOf("pdf", "txt"),
)
```

Not every platform enforces the filter, so check `file.extension` if your app needs a specific format.

## Download file on the web

Browsers don't let you choose a save location: use `FileKit.download` to send bytes to the user's downloads folder instead. See [Download files](https://filekit.mintlify.site/core/web.md#download-files).

## Platform notes

| Platform | Behavior |
| - | - |
| Android | Opens the system "Create document" screen, which creates an empty file at the chosen location. With several `allowedExtensions`, the MIME type falls back to `*/*`. |
| iOS | Exports a temporary placeholder file through the Files picker, then removes it so you can write to the returned location. `allowedExtensions` is ignored. |
| Desktop | The save dialog shows `dialogSettings.title` on Linux native, Windows native, and JVM on macOS. The macOS native saver and the JVM savers on Windows and Linux ignore it. |
| Linux native | Needs a running XDG Desktop Portal. See [Dialogs setup](https://filekit.mintlify.site/dialogs/setup.md#linux-setup). |
| Web | Not available. Use `FileKit.download`. |

> [accordion] Upgrading from older versions
>
> The `extension` parameter of `openFileSaver` and `launch()` is deprecated. Rename it to `defaultExtension`; the behavior is the same.

## Related

* [Writing files](https://filekit.mintlify.site/core/write-file.md) for streaming large content.
* [Dialog settings](https://filekit.mintlify.site/dialogs/dialog-settings.md) for titles and parent windows.


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