I am trying to implement a proxy that forwards a post request. (Play 2.5.15 Framework and Scala 2.11.11) The request is a multipart call which can contain a huge file, that I can't store in memory nor on disk as a temp file. I found a code snipped in the documentation (https://www.playframework.com/documentation/2.5.x/ScalaBodyParsers#directing-the-body-elsewhere) which would probably do the trick.
import javax.inject._
import play.api.mvc._
import play.api.libs.streams._
import play.api.libs.ws._
import scala.concurrent.ExecutionContext
import akka.util.ByteString
class MyController @Inject() (ws: WSClient)(implicit ec: ExecutionContext) {
def forward(request: WSRequest): BodyParser[WSResponse] = BodyParser { req =>
Accumulator.source[ByteString].mapFuture { source =>
request
// TODO: stream body when support is implemented
// .withBody(source)
.execute()
.map(Right.apply)
}
}
def myAction = Action(forward(ws.url("https://example.com"))) { req =>
Ok("Uploaded")
}
}
unfortunately the stream body support is not available, yet. Is there a way to achieve it? I couldn't find a suitable solution on the net. I am an absolute scala and play rookie so I am thankful for every hint.