I want to return image/PNG
as response to calling URL. How can I do it in Spray?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This may help:
import java.io._
import spray.http._
import MediaTypes._
sender ! HttpResponse(entity = HttpEntity(`image/png`, HttpData(new File("my.png"))))
See also, HttpMessage, HttpEntity, HttpData and MediaTypes. You can do same for HttpRequest
as well. You can use Array[Byte]
or ByteString
instead of File
. Checked for Spray 1.3.x.