https://kotlinlang.org logo
#ktor
Title
# ktor
j

Joey

03/25/2022, 3:34 PM
Are there any good examples on how to do streaming (body) uploads?
a

Aleksei Tirman [JB]

03/26/2022, 5:31 PM
Here is an example of streaming a request body that is read from a file:
Copy code
import io.ktor.client.*
import io.ktor.client.engine.apache.*
import io.ktor.client.features.cache.*
import io.ktor.client.request.*
import io.ktor.util.cio.*
import java.io.File

suspend fun main() {
    val client = HttpClient(Apache) {
        install(HttpCache)
    }

    val file = File("/path/to/file")

    val r = <http://client.post|client.post><String>("<https://httpbin.org/post>") {
        body = file.readChannel()
    }

    println(r)
}
3 Views