Skip to content

Instantly share code, notes, and snippets.

@cdmckay
Created June 24, 2015 05:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdmckay/5f05cbcb5327259df1cf to your computer and use it in GitHub Desktop.
Save cdmckay/5f05cbcb5327259df1cf to your computer and use it in GitHub Desktop.
An example of how to use MultipartFormDataWriteable
import play.api.libs.ws.WS
import play.api.mvc.MultipartFormData.FilePart
import play.api.mvc.MultipartFormData
import utilities.MultipartFormDataWriteable._
...
val url = "https://example.com"
val dataParts = Map(
"foo" -> Seq("bar"),
"alice" -> Seq("bob")
)
val file = new jave.io.File(... path to a jpg ...)
val fileParts = Seq(new FilePart("attachment", "foo.jpg", Some("image/jpeg"), file)
val multipartFormData = MultipartFormData(dataParts, fileParts, Seq(), Seq())
WS.url(url).post(multipartFormData)
@ergomesh
Copy link

what is

import utilities.MultipartFormDataWriteable._

the old ning methods don't work and yours seems promising on 2.4.x

I found it http://cdmckay.org/blog/2015/06/24/how-to-add-support-for-posting-multipart-forms-to-the-play-scala-ws-library/

but it still doesnt work in play2.4 x :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment