Let users pick photos and videos with the native gallery on Android and iOS
Pass FileKitType.Image, Video, or ImageAndVideo to the file picker. On Android and iOS it opens the system photo picker; on other targets it opens a file dialog filtered to media files.
Usage
val launcher = rememberFilePickerLauncher( type = FileKitType.Image, onError = { failure -> showError(failure.message) },) { image -> // image is a PlatformFile, or null when the user cancelled}Button(onClick = { launcher.launch() }) { Text("Pick a photo")}
val image: PlatformFile? = FileKit.openFilePicker(type = FileKitType.Image)
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.Every file picker option applies, including the state-tracking modes.
Try it
This is the FileKit sample running in your browser. Choose images, videos, or both, switch the selection mode, then open a file to inspect its metadata. In a browser the picker is a file input filtered to media files.
What users see
Platform
Dialog
Android
The system Photo Picker. If the device has none, FileKit opens the document picker filtered by image/* or video/*.
iOS
PHPickerViewController. FileKit copies each selected item to a temporary directory before returning it.
macOS, JVM, Linux native, Windows native
The regular file dialog, filtered to png, jpg, jpeg, gif, bmp for images and mp4, mov, avi, mkv, webm for videos.
Web
<input type="file"> with accept set to image/*, video/*, or both.
Limit the number of items
Use FileKitMode.Multiple(maxItems) with a value from 1 to 50. The same mode works on rememberFilePickerLauncher:
val media: List<PlatformFile>? = FileKit.openFilePicker( type = FileKitType.ImageAndVideo, mode = FileKitMode.Multiple(maxItems = 5),)
The iOS picker and the Android Photo Picker enforce the limit in their UI. When Android falls back to the document picker, and on other targets, the dialog can’t limit the selection, so FileKit keeps the first maxItems files.
iOS can return photos as HEIC, which some image decoders and servers can’t read. In iosMain, pass FileKitDialogSettings(assetRepresentationMode = FileKitAssetRepresentationMode.Compatible) as dialogSettings so iOS transcodes them to a more compatible format.