akka-http represents a file uploaded using multipart/form-data encoding as Source[ByteString, Any]
. I need to unmarshal it using Java library that expects an InputStream
.
How Source[ByteString, Any]
can be turned into an InputStream
?
As of version 2.x you achieve this with the following code:
import akka.stream.scaladsl.StreamConverters
...
val inputStream: InputStream = entity.dataBytes
.runWith(
StreamConverters.asInputStream(FiniteDuration(3, TimeUnit.SECONDS))
)
Note: was broken in version 2.0.2 and fixed in 2.4.2