play Framework 2.0に大きなファイル(1 MBを超える)をアップロードすると、
"413 Request Entity Too Large"エラー。
誰かがこれを取り除く方法を提案してもらえますか?
ありがとう、
[〜#〜] update [〜#〜]これをapplication.confに追加することで、この問題を解決しました
parsers.MultipartFormData.maxLength = 10240K
http://www.playframework.com/documentation/2.0.x/ScalaBodyParsers を参照してください
またはJavaバージョン: http://www.playframework.com/documentation/2.0.x/JavaBodyParsers
エキス:
// Accept only 10KB of data.
def save = Action(parse.text(maxLength = 1024 * 10)) { request =>
Ok("Got: " + text)
}
また、application.conf
を使用してparsers.text.maxLength
でこれを構成できます。
_parse.multipartFormData
_および_parse.temporaryFile
_は、引数としてmaxLength
を使用しないため、parse.text(maxLength)
のようにデフォルトを増減できます。
ただし、代わりにparse.maxLength(maxLength, wrappedBodyParser)
を使用できます。
_// accepts 10 MB file upload
def save = Action(parse.maxLength(10 * 1024 * 1024, parse.multipartFormData)) { request =>
request.body match {
case Left(MaxSizeExceeded(length)) => BadRequest("Your file is too large, we accept just " + length + " bytes!")
case Right(multipartForm) => {
/* Handle the POSTed form with files */
...
}
}
}
_
Playバージョン2.4.xの場合:
Rawパーサーやmultipart/form-dataなど、ディスク上のコンテンツをバッファリングするパーサーの場合、コンテンツの最大長はplay.http.parser.maxDiskBufferプロパティ。デフォルトは10MBです。 multipart/form-dataパーサーは、データフィールドの集計にtext maxlengthプロパティも適用します。
https://www.playframework.com/documentation/2.4.x/ScalaBodyParsers
私の場合、AJAXリクエストでエラーが発生しました(長いテキストでした)。このようなリクエストの場合、プロパティを設定できます。
parsers.text.maxLength = 1024K
Playドキュメントの詳細: https://www.playframework.com/documentation/2.0/JavaBodyParsers
AnyContent
パーサーを使用しています。構成が機能しなかったため、controller
コードを次のように変更する必要がありました
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
}
}