vinceglb / FileKit

Pick and save Files, Medias and Folder for Kotlin Multiplatform / KMP and Compose Multiplatform / CMP
https://vinceglb.github.io/FileKit/
MIT License
598 stars 16 forks source link

How to save image to gallery iOS #100

Open BoikoIlya opened 2 months ago

BoikoIlya commented 2 months ago

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

vinceglb commented 2 months ago

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.

fethij commented 1 month ago

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