Rabzu Rabzu - 1 year ago 112
Scala Question

How to transform Bytestring to Source[Bytestring, Any]

I'm receiving a file as a Bytestring from Kafka Reactive Streams consumer; I want to construct an akka-http request with this Bytestring as an entity HttpEntity.Default. HttpEntity.Default requires Source[Bytestring, Any] as one of its parameters.

What is a best way to connect the two?

Answer Source

You can use Source.single:


That said, are you really sure you need exactly HttpEntity.Default? You can use the HttpEntity.apply(ContentType, ByteString) method to construct an entity directly out of a ByteString:

HttpEntity(ContentTypes.`application/octet-stream`, byteString)

It returns an instance of HttpEntity.Strict instead of HttpEntity.Default, but Strict can be used for sending HTTP requests just fine.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download