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

# Coil 3

> Display a PlatformFile image with Coil 3 AsyncImage

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

`filekit-coil` lets [Coil 3](https://coil-kt.github.io/coil/) load a `PlatformFile` directly, so you can pass a picked file to `AsyncImage` as its `model`.

## Usage

```kotlin build.gradle.kts theme={null}
implementation("io.github.vinceglb:filekit-coil:0.17.0")
```

```toml libs.versions.toml theme={null}
[versions]
filekit = "0.17.0"

[libraries]
filekit-coil = { module = "io.github.vinceglb:filekit-coil", version.ref = "filekit" }
```

Register `PlatformFile` support once, in your root composable:

```kotlin theme={null}
import io.github.vinceglb.filekit.coil.addPlatformFileSupport

@Composable
fun App() {
    setSingletonImageLoaderFactory { context ->
        ImageLoader.Builder(context)
            .components { addPlatformFileSupport() }
            .build()
    }

    MaterialTheme { /* your content */ }
}
```

Then use a `PlatformFile` as the model:

```kotlin theme={null}
@Composable
fun Gallery(files: List<PlatformFile>, modifier: Modifier = Modifier) {
    LazyColumn(modifier) {
        items(files) { file ->
            AsyncImage(
                model = file,
                contentDescription = file.name,
                contentScale = ContentScale.Crop,
                modifier = Modifier.fillMaxWidth().height(200.dp),
            )
        }
    }
}
```

If you build your own `ImageLoader` instead of the singleton, call `addPlatformFileSupport()` in its `components` block.

## Load files that need security-scoped access

Coil reads the file itself, without the security-scoped access FileKit starts around its own operations. Call `securelyAccessFile` from `onState` when the file comes from:

* the file or directory picker on iOS, which return files outside your app's sandbox;
* a [bookmark](https://filekit.mintlify.site/core/bookmark-data.md) restored on iOS, or on macOS (native or JVM) when the app is sandboxed.

```kotlin theme={null}
import io.github.vinceglb.filekit.coil.securelyAccessFile

AsyncImage(
    model = file,
    contentDescription = file.name,
    onState = { state -> state.securelyAccessFile(file) },
)
```

It starts access when loading begins and stops it on success or error. You don't need it for gallery and camera results (on iOS, FileKit writes them into your app's temporary or cache folder), for files in your [app directories](https://filekit.mintlify.site/core/file-utils.md), or on Android and the web. Elsewhere it is a no-op, so calling it from common code is safe.

## Related

* [Image and video utilities](https://filekit.mintlify.site/core/image-and-video-utils.md) to compress images or get an `ImageBitmap`.
* [Gallery picker](https://filekit.mintlify.site/dialogs/gallery-picker.md) to let users pick photos.
* [Coil documentation](https://coil-kt.github.io/coil/getting_started/) for transformations, placeholders, and caching.


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