How to return image/png media type response in Spray?

妖精的绣舞 提交于 2019-12-13 02:27:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!