Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play 2.5 Migration Error: Custom Action with BodyParser: could not find implicit value for parameter mat: akka.stream.Materializer

I have a Play Framework application, version 2.4 migrating to 2.5, everything done ! but throw an error in my custom action with BodyParser,

 def isAuthenticatedAsync[A](parser: BodyParser[A])(f: => Long => Request[A] => Future[Result]) = {
Security.Authenticated(userId, onUnauthorized) { user =>
  Action.async(parser)(request => f(user)(request))
}

}

Use this:

def upload = isAuthenticatedAsync(parse.maxLength(5 * 1024 * 1024, parse.multipartFormData)) { userId => request =>
//Logger.info(s"")
request.body match {
  case Left(MaxSizeExceeded(length)) => Future(BadRequest(Json.toJson(ResultTemp("Your file is too large, we accept just " + length + " bytes!"))))
  case Right(multipartForm) =>

throw an error:

could not find implicit value for parameter mat: akka.stream.Materializer

[error] def upload = Action.async(parse.maxLength(5 * 1024 * 1024, parse.multipartFormData)) { request =>

like image 552
Đạt Thành Avatar asked Mar 15 '16 06:03

Đạt Thành


1 Answers

Looks like you need to inject a materializer in your controller

class MyController @Inject() (implicit val mat: Materializer) {}
like image 53
Jonas Anso Avatar answered Oct 17 '22 01:10

Jonas Anso