2012-03-29 32 views
1

我試圖從play-mini應用程序提供圖像。Play-mini:如何返回圖像

object App extends Application { 
    def route = { 
    case GET(Path("/image")) => Action { request => 
     Ok(Source.fromInputStream(getClass.getResourceAsStream("image.gif")).toArray).as("image/gif") 
    } 
    } 
} 

不幸的是,這樣做NOE工作:)我收到以下錯誤

Cannot write an instance of Array[Char] to HTTP response. Try to define a Writeable[Array[Char]] 

回答

2

不知道play-mini,但在play20有預定義Writeable[Array[Byte]],所以您需要爲文件提供Array[Byte]處理。另外,關於在play20中提供文件的服務有點documentation

+0

Thx爲鏈接。它幫我弄明白了:) – rompetroll 2012-03-29 13:26:18

+0

這個工程:Ok.stream(Enumerator.fromStream(getClass.getClassLoader.getResourceAsStream(「image.gif」))) – rompetroll 2012-03-29 13:27:01