FileKit icon indicating copy to clipboard operation
FileKit copied to clipboard

How to save image to gallery iOS

Open BoikoIlya opened this issue 1 year ago • 2 comments

I have image as byte array, how to save it to gallery iOS?? help please

BoikoIlya avatar Aug 30 '24 20:08 BoikoIlya

Hi @BoikoIlya!

By using the Save File Picker UI, you can do it like explain in the documentation:

val image: ByteArray

// FileKit Core
val file = FileKit.saveFile(
    baseName = "image",
    extension = "png",
    initialDirectory = "/custom/initial/path",
    bytes = image
)

// FileKit Compose
val launcher = rememberFileSaverLauncher() { file ->
    // Handle the saved file
}
launcher.launch(
    baseName = "image",
    extension = "png",
    initialDirectory = "/custom/initial/path",
    bytes = image
)

And you need to find a way to get the url of the gallery in iOS that you can pass it to initialDirectory parameter.

If you want to save direct bytes to a file without using picker UI, you'll need to code this yourself as it's not supported yet with FileKit.

vinceglb avatar Sep 02 '24 16:09 vinceglb

this may help: https://github.com/fethij/Rijksmuseum/blob/main/feature/arts/src/iosMain/kotlin/Utils.ios.kt#L47

fethij avatar Oct 01 '24 14:10 fethij

It's now possible to save an image to the gallery on Android and iOS using FileKit version 0.10.0-beta01.

You can read the documentation here: https://filekit.mintlify.app/core/image-utils#saving-images-to-gallery

vinceglb avatar Mar 04 '25 13:03 vinceglb