Note to self: Play-WS Scala send POST Request Multipart/Form-Data

import play.api.mvc.MultipartFormData._

val url = "http://someAddress.com/withPostEndpoint"

val params: immutable.Iterable[DataPart] = Map(
  "from" -> "sender@host.com",
  "to" -> "user@host.com",
  "subject" -> "mySubject",
  "text" ->
    s"""
       |Hallo!
       |blablabla
       | """.stripMargin
).map { case (k, v) => DataPart(k, v) }

val parameterSource = Source.fromIterator(() => params.toIterator)

val f = wsClient
  .url(url)
  .post(parameterSource)

Leave a comment

Your email address will not be published. Required fields are marked *