BodyParser[MultipartFormData[Source[ByteString, _]]def handleFilePartAsFile: FilePartHandler[Source[ByteString, _]] = {
case FileInfo(partName, filename, contentType) =>
Accumulator
.source[ByteString]
.map { source =>
println("Hey, I'm here")
FilePart(partName, filename, contentType, source)
}
}
def experimental = Action(parse.multipartFormData(handleFilePartAsFile)) { implicit req =>
val retString = req.body.files
.map { filePart =>
//stream source encapsulated in filePart...
filePart.toString
}
.mkString(" -- ")
Ok(retString)
}
Extreme care must be taken when using this accumulator - the source must always be materialized and consumed. If it isn't, this could lead to resource leaks and deadlocks upstream.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/16fea9d7-64aa-4f37-8cae-b8fc231625ce%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
Thanks Greg,
Yes, in the second example I do consume the source and works. Concretely, I want to stream files elsewhere upon files uploads.
However, more generally, ideally I would be able to obtain the Source[ByteString, _] of each FilePart as a library-like utility (in a BodyParser), so that later different controllers’ Actions can do different things with those sources. What I would like is a general BodyParser that returns a Source[ByteString, _] and another parser that returns a MultipartFormData of type Source[ByteString, _]
I tested making a BodyParser that returns the whole Source[ByteString, _] of the body, and works (pretty much as in in this doc, but without making a WSClient call, just returning the Source.
I also saw that Play 2.6.x implemented a new BodyParser that returns a ByteString.
Makes sense?
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/16fea9d7-64aa-4f37-8cae-b8fc231625ce%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Play Framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/bw3MEedbFhM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/CAA%3D11HxbQc2zBsXav12vWQ%2B2%2BYO5_4R-i-U3ORO0up_Q%3Dx%2B8MA%40mail.gmail.com.