Create a BodyParser to parse MultipartFormData directly to a stream
#9,852 opened on Nov 27, 2019
Repository metrics
- Stars
- (12,623 stars)
- PR merge metrics
- (Avg merge 10d 17h) (69 merged PRs in 30d)
Description
Play Version
2.7
API
Scala (Ideally, both)
Feature Description
As of now, the documentation only details how to use parse.multipartFormData and parse.temporaryFile. Both approaches store temporary files, which is not ideal in a Dockerized deployment. The alternative that is suggested is to create your own BodyParser to handle the bytes as they stream in.
I propose that a multipartFormData parser should be created, which provides the body as an Akka Stream (of type Source[ByteString, Any]. This will allow you to skip storing temporary files, and gives you an idiomatic and recommended way to handle the bytes by passing it to the next destination. This is especially helpful for use cases where you are using Play as a simple frontend or gateway, and just want to pass the bytes anyway.
Providing a streamed approach encourages developers to evaluate streaming as a solution for handling files. Right now, the recommendation to build your own BodyParser deters new developers from considering anything outside of temporary file storage.