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

# Share file

> Open the native share sheet for one or more files on Android and iOS

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

Open the system share sheet so the user can send files to another app. Call it from a source set that only includes Android and iOS, such as `mobileMain` (see [shared source sets](https://filekit.mintlify.site/platform-support.md#use-platform-specific-apis-from-shared-code)).

![iOS share sheet for a JPEG image, with Reminders, Copy, Print, and Assign to Contact actions](https://mintcdn.com/filekit/CkpVFgz9dKnI5cGG/images/share-file-ios.png?fit=max\&auto=format\&n=CkpVFgz9dKnI5cGG\&q=85\&s=021252783dbb079afaba614388dd5384)

![Android share sheet previewing an image, with Quick Share, Photos, Print, Drive, and Maps targets](https://mintcdn.com/filekit/CkpVFgz9dKnI5cGG/images/share-file-android.png?fit=max\&auto=format\&n=CkpVFgz9dKnI5cGG\&q=85\&s=1e6a3d0a4c33a6676781bac89f6947c8)

## Usage

```kotlin Compose theme={null}
val launcher = rememberShareFileLauncher(
    onError = { failure -> showError(failure.message) },
)

Button(onClick = { launcher.launch(FileKit.filesDir / "report.pdf") }) {
    Text("Share")
}
```

```kotlin Suspend API theme={null}
FileKit.shareFile(FileKit.filesDir / "report.pdf")

// Several files at once
FileKit.shareFile(listOf(FileKit.filesDir / "a.jpg", FileKit.filesDir / "b.jpg"))
```

Sharing has no result: a completed share and a dismissed sheet look the same. 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#sharing).

## Options

**file / files** `PlatformFile | List\<PlatformFile\>`

What to share. An empty list does nothing.

**shareSettings** `FileKitShareSettings` (default: createDefault())

Platform-specific settings. In the suspend API, pass it to `shareFile()`.

**properties**

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

FileProvider authority, only needed for files outside `filesDir` and `cacheDir`. When `null`, FileKit uses its bundled `${applicationId}.FileKitFileProvider`.

**addOptionChooseIntent** `(Intent) -\> Unit` (default: no-op)

Customizes the chooser `Intent` before it launches.

**addOptionUIActivityViewController** `(UIActivityViewController) -\> Unit` (default: no-op)

Customizes the share sheet before it appears, for example `excludedActivityTypes`.

**presenter** `UIViewController?` (default: null)

View controller that presents the sheet. When `null`, the suspend API uses the top-most view controller and the Compose launcher uses the current `LocalUIViewController`.

**metaTitle** `String` (default: "Share File")

Accepted but currently not applied to the share sheet.

## Platform notes

| Platform | Behavior |
| - | - |
| Android | Files in `FileKit.filesDir`, `FileKit.cacheDir`, or returned by a picker (`content://`) share without setup. The MIME type comes from the file extensions, or `*/*` when they differ. The suspend call returns once the chooser opens. |
| iOS | The suspend call returns when the sheet closes. An error reported by the chosen activity fails with a `FileKitDialogException`. On iPad, the sheet opens as a popover centered on the presenter's view. |

## Android setup

Only needed for files outside `FileKit.filesDir` and `FileKit.cacheDir`. `filekit-dialogs` already ships a FileProvider (`${applicationId}.FileKitFileProvider`) that covers those two directories, and `content://` files returned by the pickers need no provider at all. For any other location, such as `getExternalFilesDir()`, `FileProvider` throws an `IllegalArgumentException` until you declare your own provider.

**1. Declare a provider in your manifest**

```xml AndroidManifest.xml theme={null}
<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>
```

**2. List the directories it may expose**

Add one entry per location you use, for example app-specific external storage:

```xml res/xml/file_paths.xml theme={null}
<paths>
    <external-files-path name="external_files" path="." />
</paths>
```

See [FileProvider](https://developer.android.com/reference/androidx/core/content/FileProvider) for every path type.

**3. Pass the authority to FileKit**

The `authority` parameter exists only on Android, so build these settings in `androidMain`:

```kotlin androidMain theme={null}
val authority = "${FileKit.context.packageName}.fileprovider"

FileKitOpenCameraSettings(authority = authority) // camera picker
FileKitShareSettings(authority = authority) // share file
FileKitOpenFileSettings(authority = authority) // open with default app
```

> [!NOTE]
>
> A custom `authority` applies to every file in the share. If you share files from several directories at once, for example `filesDir` and `getExternalFilesDir()`, your provider's `file_paths.xml` must cover all of them. Otherwise FileKit throws an `IllegalArgumentException` before the share sheet opens.

## Related

* [Open with default app](https://filekit.mintlify.site/dialogs/open-file.md) to view a file instead of sending it.
* [Camera picker](https://filekit.mintlify.site/dialogs/camera-picker.md) to capture a photo to share.


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