I think I miss something here...
What is the proper way to send a Kotlin ByteArray from a client to a server?
This is what I tried:
val client = HttpClient()
val response: HttpResponse = <http://client.post|client.post>("<http://localhost:8080/upload>") {
contentType(ContentType.Application.OctetStream)
setBody(bytes)
}
fun Application.configureRouting() {
routing {
get("/") {
call.respondText("<http://stefan-oltmann.de|stefan-oltmann.de>")
}
post("/upload") {
val byteArray = call.receiveStream().readBytes()
println("Received bytes: ${byteArray.size}")
val saveGame = SaveGameReader.readSaveGame(byteArray)
val summary = saveGame.createSummary()
call.respondText(summary.toString())
}
}
}
I run into this error:
2024-01-01 23:15:39.439 [eventLoopGroupProxy-4-1] TRACE io.ktor.routing.Routing - Trace for [upload]
/, segment:0 -> SUCCESS @ /
/, segment:0 -> SUCCESS @ /
/(method:GET), segment:0 -> FAILURE "Selector didn't match" @ /(method:GET)
/upload, segment:1 -> SUCCESS @ /upload
/upload/(method:POST), segment:1 -> FAILURE "Selector didn't match" @ /upload/(method:POST)
/health, segment:0 -> FAILURE "Selector didn't match" @ /health
Matched routes:
No results
Route resolve result:
FAILURE "No matched subtrees found" @ /