v

    vanniktech

    2 years ago
    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.
    matej

    matej

    2 years ago
    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

    vanniktech

    2 years ago
    Nope I haven’t
    Kivia Brito

    Kivia Brito

    2 years ago
    This is how I am converting an image(data) to KotlinByteArray in Swift.
    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)
      }
    matej

    matej

    2 years ago
    @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.