https://kotlinlang.org logo
Title
i

Ifvwm

01/14/2021, 6:07 AM
httpClient.put<ByteArray>(realUrl){
            body = "aha".toByteArray()
        }
this code can upload data to a link, now I need to get upload progress, how to use a outputStream to instead of this way to upload data?
val _outputStream = httpClient.put<HttpResponse>(realUrl)
        val outputStream = _outputStream.receive<OutputStream>()

        outputStream.write("abc".toByteArray())
        outputStream.flush()
        outputStream.close()
this won't work, error message o.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel (Kotlin reflection is not available) -> class java.io.OutputStream (Kotlin reflection is not available)
g

gildor

01/14/2021, 6:27 AM
you cannot receive OutputStream
you can use ByteWriteChannel
See sample here (it for download, but it’s the same idea): https://ktor.io/docs/streaming.html
i

Ifvwm

01/14/2021, 6:44 AM
val aa = httpClient.put<HttpResponse>(realUrl)
    val ab = aa.receive<ByteWriteChannel>()
    ab.write("abc")
    ab.flush()
    
    val ac = httpClient.put<ByteWriteChannel>(realUrl)
    ac.write("abc")
    ac.flush()
like this? there're no much info on that doc