Marcel Bochtler
06/07/2023, 11:24 AMval fileChannel: ByteReadChannel = client.get("<https://example.com/bigfile.bin>").body()
call.response.header(
HttpHeaders.ContentDisposition,
ContentDisposition.Attachment.withParameter(
ContentDisposition.Parameters.FileName,
fileName
).toString()
)
call.respond(fileChannel)
the the Profiler shows that a large amount of memory is used by a byte[]
.
What do I miss here? Where is the ByteReadChannel
converted into a byte array, and therefore read into memory?Aleksei Tirman [JB]
06/07/2023, 1:42 PMget
call reads the entire response body into memory. You can use the following code to stream the response body:
client.prepareGet("<https://example.com/bigfile.bin>").execute { response ->
call.respond(response.bodyAsChannel())
}