natario1
08/08/2023, 3:18 PMjava.io.File
like this?
val channel = file.readChannel()
return <http://ktor.post|ktor.post>("endpoint") {
setBody(channel)
contentType(ContentType.Application.OctetStream)
}.body()
Server returns 500 and I’m trying to understand if it’s my fault or not. I found readChannel()
by accident, but it seemed useful in order to avoid loading the whole file in JVM memory as a ByteArray for example.natario1
08/08/2023, 3:32 PMsetBody(ChannelWriterContent(
contentType = contentType,
body = {
val read = file.readChannel()
read.copyTo(this)
}
))
It fails too. setBody(file.readBytes())
works.Aleksei Tirman [JB]
08/09/2023, 7:02 AMval channel = File("path/to/file").readChannel()
val client = HttpClient()
val response = <http://client.post|client.post>("<https://httpbin.org/post>") {
setBody(channel)
contentType(ContentType.Application.OctetStream)
}
println(response.bodyAsText())
natario1
08/09/2023, 9:35 AMreadChannel()
with readBytes()
, our server is happy, otherwise it isn’t. So this line creates some difference in the outgoing request, but I can’t figure out whatAleksei Tirman [JB]
08/09/2023, 9:37 AMreadChannel
the Transfer-Encoding: chunked
header is sent.natario1
08/09/2023, 10:18 AM