Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"missing boundary headers" with ws.url in scala play

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?

like image 865
fredley Avatar asked Dec 03 '25 17:12

fredley


1 Answers

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.

like image 119
bluenote10 Avatar answered Dec 06 '25 11:12

bluenote10



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!