问题
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.
来源:https://stackoverflow.com/questions/28125752/how-to-return-image-png-media-type-response-in-spray