Play WS (2.2.1): post/put large request

2019-07-19 00:21发布

I'm using Play.WS to issue http requests. My goal is to send a put request with a large file.

val requestHolder = WS.url("http://" + host)
requestHolder.put(???)

I don't know what should be the type of ??? to stream the body. The requestHolder has a put(File file) method - which I can't use because I don't have the file - and put[T](T body) where T can be anything as long as you have an instance of Writable[T].

There are some default writables defined for json, text, xml, etc. But non for an InputStream for example.

The documentation gives a (brief) hint to handle large responses but nothing about large requests (http://www.playframework.com/documentation/2.2.x/ScalaWS)

Anyone knows how to define a writable that would accept an InputStream? Or maybe an Iteratee?

2条回答
唯我独甜
2楼-- · 2019-07-19 01:13

Unfortunately, this isn't supported yet.

There is a little discussion about it here:

https://github.com/playframework/playframework/pull/1510

And we're hoping that for Play 2.3, we will have a solution to allow it.

查看更多
小情绪 Triste *
3楼-- · 2019-07-19 01:21

WS underlying client takes InputStream. Access it like this:

import com.ning.http.client.AsyncHttpClient

val client:AsyncHttpClient = WS.client
查看更多
登录 后发表回答