Has anyone been able to convert a file from an iOS...
# multiplatform
v
Has anyone been able to convert a file from an iOS system into a KotlinByteArray? I want to upload an image using ktor and ByteArray is the common denominator between the platforms. Android side is already working.
1
m
Did you ever solve this? ByteArray is a bit dangerous, isn't it? You have to read the whole image into memory in that case, and this could cause low memory warnings/errors if the image is big. I'm having the same conundrum now, but with uploading audio files, which can get even bigger.
v
Nope I haven’t
k
This is how I am converting an image(data) to KotlinByteArray in Swift.
Copy code
let swiftByteArray = [UInt8](data)
  let intArray : [Int8] = swiftByteArray.map { Int8(bitPattern: $0) }
  let kotlinByteArray: KotlinByteArray = KotlinByteArray.init(size: Int32(swiftByteArray.count))
  for (index, element) in intArray.enumerated() {
   kotlinByteArray.set(index: Int32(index), value: element)
  }
m
@Kivia Brito I ended up doing something similar, it works for my use case (upload) for now, but I'll have to replace it with a buffered/chunked solution eventually. A couple of hundred megabyte file is not gonna be fun to load into a byte array in its entirety.
👍 1