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
saket
09/11/2021, 6:11 AM
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
Igor Maric
09/13/2021, 8:33 AM
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
Zhiqiang Bian
09/14/2021, 12:17 PM
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.