Max file upload size in Play framework 2.0

后端 未结 5 1465
慢半拍i
慢半拍i 2020-12-14 07:49

When I upload large files (greater than 1 MB) in play framework 2.0 I get

"413 Request Entity Too Large" error.

Cou

5条回答
  •  离开以前
    2020-12-14 08:13

    I am using an AnyContent Parser. I had to change to controller code to following as the configurations didn't work for me

     def newQuestion = silhouette.SecuredAction.async(parse.maxLength(1024 * 1024, parse.anyContent)(ActorMaterializer()(ActorSystem("MyApplication")))) { 
        implicit request => {
          println("got request with body:" + request.body)
          val anyBodyErrors: Either[MaxSizeExceeded, AnyContent] = request.body
          anyBodyErrors match {
            case Left(size) => {
              Future {
                EntityTooLarge(Json.toJson(JsonResultError(messagesApi("error.entityTooLarge")(langs.availables(0)))))
              }
            }
            case Right(body) => {
    
              //val body:AnyContent = request.body
              val jsonBodyOption = body.asJson
    }
    }
    

提交回复
热议问题