Featured image of post 【PlayFramework2.7系】HttpStatasu413の「Request Entity Too Large」が出た場合の原因と解決方法【play.http.parser.maxDiskBuffer】

【PlayFramework2.7系】HttpStatasu413の「Request Entity Too Large」が出た場合の原因と解決方法【play.http.parser.maxDiskBuffer】

428文字

リクエスト容量の超過

PlayFrameworkを使ってファイルの送信フォームを作っている際に、特に設定を変えずに10MB以上のデータを送信するとHttpStatus413Request Entity Too Largeのようなエラーが出力されます。

これは、PlayFrameworkのデフォルトの設定値である10MB超えるデータ量になっている事が原因です。

For parsers that buffer content on disk, such as the raw parser or multipart/form-data, the maximum content length is specified using the play.http.parser.maxDiskBuffer property, it defaults to 10MB. The multipart/form-data parser also enforces the text max length property for the aggregate of the data fields.Scala Body Parsers - 2.7.x

解決方法

play.http.parser.maxDiskBufferを変更

上限値を広げるには、conf/application.confplay.http.parser.maxDiskBufferの値に上限値を指定する事で拡張する事が可能です。

例として、200MBにあげるには以下のように指定すればOKです。

conf/application.conf
...
(略)
...
play {
  http {
    parser{
      maxDiskBuffer=200MB
    }
  }

}
...
(略)
...

終わりに

以上のように、PlayFrameworkの設定ファイルに一行追記するだけで対応する事が可能です。

複数画像をまとめてあげる機能を実現するにはほぼ必須の設定だと思うので、ぜひ試してみてください♪