One of the example projects listed by Lightbend is not working for larger files

At this page, https://developer.lightbend.com/start/?group=play, we can find a list of example projects. Among these examples, there is one project is about Java File Upload (https://developer.lightbend.com/start/?group=play&project=play-samples-play-java-fileupload-example). This project works for small files, but if you try to upload a larger file, for example, which has a size about 15M, we will get a page says “The connection was reset”.

Does anyone have any idea about this?

Found something in the document (https://www.playframework.com/documentation/2.8.x/JavaBodyParsers#Content-length-limits): " … the disk buffer limit is configured using play.http.parser.maxDiskBuffer , and defaults to 10MB". My file did go above 10MB, so likely this is the reason.

So that is some progress and I added the following to application.conf:

play.http.parser.maxMemoryBuffer=1024k
play.http.parser.maxDiskBuffer=20480K

which unfortunately still does not help. So if you have any idea on this, please kindly let me know.

It’s strange, I used the following configuration in application.conf and I’m able to upload files greater than 1GB

play.http.parser.maxMemoryBuffer = 256kB
play.http.parser.maxDiskBuffer = 2GB 

Hi morellik,

I hope you are still coming back to this site…

Anyway, I tried your parameters, and I still cannot upload file. Here is what I have in my log:

2021-01-21 22:17:13,068 [INFO] from controllers.MyMultipartFormDataBodyParser in play-dev-mode-akka.actor.default-dispatcher-69 - config.parser().maxDiskBuffer() = 2000000000
2021-01-21 22:17:13,068 [INFO] from controllers.MyMultipartFormDataBodyParser in play-dev-mode-akka.actor.default-dispatcher-69 - config.parser().maxMemoryBuffer() = 256000
2021-01-21 22:17:13,093 [WARN] from play.filters.CSRF in play-dev-mode-akka.actor.default-dispatcher-69 - [CSRF] Check failed because no or invalid token found in body for /upload
2021-01-21 22:17:13,093 [WARN] from play.filters.CSRF in play-dev-mode-akka.actor.default-dispatcher-69 - [CSRF] Check failed with NoTokenInBody for /upload

notice I am using config.parser().maxMemoryBuffer() = 256000, and if I try to upload a file that is smaller than 256000 bytes, it works just fine!

So this is strange. Did you have to make any other change after you download the project? are you which version of Play! are you using?

Thank you very much!

Hi IeeYu

I upgraded my app to 2.8.6 Play version and my configuration variables are:

play.http.parser.maxMemoryBuffer = 256kB
play.http.parser.maxDiskBuffer = 2GB
play.temporaryFile {
  reaper {
    enabled = true
    initialDelay = "5 minutes"
    interval = "30 seconds"
    olderThan = "30 minutes"
  }
}

The application is running on a machine with 32GB RAM using java 15.

thank you very much for the reply. It still does not work for me - the file size cannot be larger than
play.http.parser.maxMemoryBuffer. This does not make sense to me because the whole idea of “streaming it”, is to be able to stream it with a much smaller memory space and without reading the whole file into the memory first. But the file size has to be smaller than play.http.parser.maxMemoryBuffer, this makes me think it might just read the whole file into memory …

Thank you so much for the help! I hope someone with a better idea can pass this place and let me know what is happening…