I'm testing a service against a dummy endpoint, with the following code:
ws.url(dummyService).withHeaders(HeaderNames.CONTENT_TYPE -> "multipart/form-data; boundary=-----{}}AAA{{}-----").post(myData)
This generates the request ok, the headers are set properly.
In my mock service, I process the response like so:
def checkData = Action(parse.multipartFormData) { request =>
request.body.files.find(_.filename.endsWith("testfail.pdf")) match {
case Some(invalidFile) => BadRequest("Parse Fail")
case None => Ok("Parse Success")
}
}
When I run the test, I get an error 400, and the following message:
For request 'POST /TEST/process' [Missing boundary header]
What am I doing wrong?
In order to use Action(parse.multipartFormData) you have to make sure that the corresponding POST request is using a form encoding of multipart/form-data (more on when to use it).
In other words you would want to define the form in your template like this:
@helper.form(action = routes.MyApp.upload, 'enctype -> "multipart/form-data") {
// ...
}
Sending a POST with a different encoding results in the [Missing boundary header] error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With