(Play 2.0) Set maximum POST size for AnyContent

后端 未结 3 835
清歌不尽
清歌不尽 2021-02-13 06:23

I\'m using Scala in Play 2.0, and I\'m getting a 413 error whenever large data (over 100KB) is POSTed to a particular endpoint. It\'s using the anyContent parser, and it\'s not

3条回答
  •  梦如初夏
    2021-02-13 07:14

    The raw body parser does not buffer the whole body into memory, it buffers the body up to a point (configured using play.http.parser.maxMemoryBuffer, defaults to 100kb), and once that is exceeded, it flushes the body to a file and starts writing it to the file, but it also has a limit on how much data it will write to a file, which is configured using play.http.parser.maxDiskBuffer, and this defaults to 10mb. Your 15mb body is probably exceeding that limit, so you need to increase play.http.parser.maxDiskBuffer accordingly. This is all explained in the documentation.

    To answer your actual question on how to stream requests, documentation for writing custom body parsers in Java is here:

    https://www.playframework.com/documentation/2.6.x/JavaBodyParsers#Writing-a-custom-body-parser

    That explains most things you need to know about how Play body parsers work and therefore how to do streaming body parsing, no point in duplicating that documentation in this answer.

提交回复
热议问题