https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

AndreiBogdan

11/09/2023, 10:05 AM
Hello. I am uploading a wav file to AWS using ktor ... and I'm not sure how to accomplish this on iOS. On Android I'm doing the following, using a ByteReadChannel and it seems to work. The problem is that I added the ktor dependency in my native Android project (not only shared module) and I'm calling this using the readChannel() on the java.io File object, but on iOS .... how do I do this? It's not like there's a ktor dependency for iOS that can give me the ByteReadChannel ... or is there ?! Any pointers? 😞 I've been stuck this past week on this issue. I guess what I would need is ... how do i get a ByteReadChannel from the iOS native side ? 😑 https://pastebin.com/f5sU5BRh
m

mbonnin

11/09/2023, 10:12 AM
You can always create your
ByteReadChannel
manually with something like what's done on the JVM:
Copy code
GlobalScope.writer(context, autoFlush = true) {
    val buffer = pool.borrow()
    try {
      while (true) {
        buffer.clear()
        val readCount = read(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining())
        if (readCount < 0) break
        if (readCount == 0) continue

        buffer.position(buffer.position() + readCount)
        buffer.flip()
        channel.writeFully(buffer)
      }
    } catch (cause: Throwable) {
      channel.close(cause)
    } finally {
      pool.recycle(buffer)
      close()
    }
  }.channel
Didn't find anything that takes a file descriptor or
okio.Source
but maybe ask in #io?
So the
GlobalScope.writer()
solution did not work? PS: when crossposting, it's better to link to the original message this way it centralises the discussion in a single place
a

AndreiBogdan

11/15/2023, 10:21 AM
Hey. Oh, good point. Thanks for that, will do it from now on.
👍 1
Yeah, no, I couldn't figure it out unfortunately ... i'm stuck 😞
m

mbonnin

11/15/2023, 10:28 AM
What is the issue with
GlobalScope.writer{}
?
a

AndreiBogdan

11/15/2023, 10:32 AM
It went a bit over my head...I couldn't figure out how to have that on the iOS side.
i tried using NSFileHandle and stuff, but ... couldn't make it work. Not sure if I was on the right path 😄