I'm trying to serve an image from a play-mini application.
object App extends Application {
def route = {
case GET(Path("/image")) => Action { request =>
Ok( Source.fromInputStream(getClass.getResourceAsStream("image.gif")).toArray ).as("image/gif")
}
}
}
Unfortunately, this does noe work :) I get the following error
Cannot write an instance of Array[Char] to HTTP response. Try to define a Writeable[Array[Char]]
Don't know about
play-mini
, but inplay20
there is predefinedWriteable[Array[Byte]]
, so you need to provideArray[Byte]
for file handling. Also, there is a bit of documentation about serving files inplay20
.