Basically I want to allow a user to download a csv file from the server. Assume the CSV file already exists on the server. A API endpoint is exposed via GET /export. How do I stream the file from Akka HTTP server to client? This is what I have so far...
Service:
def export(): Future[IOResult] = {
FileIO.fromPath(Paths.get("file.csv"))
.to(Sink.ignore)
.run()
}
Route:
pathPrefix("export") {
pathEndOrSingleSlash {
get {
complete(HttpEntity(ContentTypes.`text/csv`, export())
}
}
}