使用高级路由api,
如何使用字节数组二进制响应完成()路由中的请求,
例如:
complete(HttpResponse(entity = HttpEntity(MediaTypes.`application/octet-stream`, byteArray)
谢谢
答案 0 :(得分:3)
使用Strict
实体类型:
import akka.util.ByteString
import akka.http.scaladsl.model.{HttpResponse, MediaTypes,HttpEntity}
val byteArray : Array[Byte] = ???
val body = ByteString(byteArray)
val entity = HttpEntity.Strict(MediaTypes.`application/octet-stream`, body)
val httpResponse = HttpResponse(entity = entity)
complete(httpResponse)