3

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?

fredley
  • 32,953
  • 42
  • 145
  • 236

1 Answers1

4

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.

Community
  • 1
  • 1
bluenote10
  • 23,414
  • 14
  • 122
  • 178