I have a file abc.txt in my project's resources folder src/main/resources. I have the following code snippet which is supposed to be serving the file.
get {
path("hello") {
complete {
val s = Source.file(new File("src/main/resources/abc.txt"), 1024)
s
}
}
I even tried the following
get {
path("hello") {
complete {
getFromFile("src/main/resources/abc.txt")
}
}
In both the cases I get an error saying
Expression of type routing.Route doesn't conform to expected Type toResponseMarshallable
My only requirement is that when I get this request I should be able to serve a file. I did google for solution I couldn't find any. Note: I am a Scala/Akka beginner
getFromFile is a Directive, while complete expects a response.
Correct solution should be like:
val route: Route =
path("hello") {
getFromResource("abc.txt")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With