Reactive send file to web service on Play! 2 Scala

I have a file in the Play app! 2, which I want to send to a web service call. I need a reactive way to read a file and send it. I want something like the following:

val source = Source.fromFile("/path/to/someFile")
val holder: WSRequestHolder = WS.url("http://example.com/service")
val futureResult = holder.post(source)
futureResult.onComplete({source.close()})

      

But the above code doesn't compile.

Is there an idiomatic way to interactively stream a file to a web service?

+3


source to share


1 answer


I found out that it is actually very easy with Play build in webservices:

WS.url("http://http://example.com/service/").post(new io.File("path/to/someFile"))

      



That is, the function post

can accept an option File

and presumably passes it correctly.

+1


source







All Articles