Hey guys! I am trying to send an image from Androi...
# multiplatform
z
Hey guys! I am trying to send an image from Android/iOS to the backend using ktor-client, which requires to convert the Image file into a ByteArray first. I can’t find a library that supports both Android and iOS. Is
expect/actual
the only way to handle this use case?
👍🏻 1
👍🏾 1
s
I'm doing something similar in my app using okio by reading the files on Android and macOS as input streams and handing them over to ktor as raw bytes.
i
I am uploading files with ByteArray. From android side I am using
file?.readBytes()
and from iOS
Copy code
let intArray : [Int8] = bytesToSend
      .map { Int8(bitPattern: $0) }
let kotlinByteArray: KotlinByteArray = KotlinByteArray.init(size: Int32(bytesToSend.count))
    for (index, element) in intArray.enumerated() {
      kotlinByteArray.set(index: Int32(index), value: element)
    }
z
I found that
okio
has an alpha release which includes a multiplatform
FileSystem
. It can decode a file into ByteArray on Android. While I have not tried it on iOS.