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

dave08

05/10/2018, 12:26 PM
Also, is there a sample for doing a file download w/ it (or even better
recieveFile
in response object...)?
d

Deactivated User

05/10/2018, 12:36 PM
I think you can use
receive<ByteReadChannel>
and copy it to a file. https://ktor.io/clients/http-client.html#HttpResponse Let me check if there is an example for that
Copy code
suspend fun downloadFile(dstFile: File, url: String, method: HttpMethod = HttpMethod.Get) {
    HttpClient(Apache.config { followRedirects = true }).call {
        this.method = method
        url(url)
    }.receiveToFile(dstFile)
}

suspend fun HttpClientCall.receiveToFile(file: File) = response.content.copyAndClose(file.writeChannel())
Does this work for you?
d

dave08

05/10/2018, 1:38 PM
Thanks, I'll try! btw, for the first question, is it stable for use on a critical Android app in production, and is the CIO client stable, or should I use another one? Also, is there a reason you don't support OkHttp client (or maybe it's just a wrapper over some other lib)?