Hi, what is the proper way to upload an image on Android and iOS using Ktor? I couldn’t find a source code or sample. Also documentation hasn’t explained to how to create a File and convert it to the ByteArray on Android and iOS
s
saket
09/29/2021, 12:50 PM
You can use okio for reading bytes and handing them over to ktor for upload
e
edenman
09/29/2021, 7:43 PM
I use this as my request body:
edenman
09/29/2021, 7:43 PM
Copy code
class ByteStreamContent(
private val readChannel: ByteReadChannel,
numBytes: Long,
override val contentType: ContentType,
) : OutgoingContent.ReadChannelContent() {
override val contentLength = numBytes
override fun readFrom() = readChannel
}
edenman
09/29/2021, 7:44 PM
and then to convert the file to a `ByteReadChannel`: