Skip to content

Instantly share code, notes, and snippets.

@mielientiev
Last active November 10, 2015 23:10
Show Gist options
  • Save mielientiev/38fec15428e8cd0b6713 to your computer and use it in GitHub Desktop.
Save mielientiev/38fec15428e8cd0b6713 to your computer and use it in GitHub Desktop.
package controllers
import play.api.libs.iteratee.{Enumeratee, Enumerator, Iteratee}
import play.api.mvc._
import scala.concurrent.Future
object Application extends Controller {
def uploadData = Action.async(uploadDataBodyParser) { request =>
println(s"Request has finished uploading. File Size: ${request.body}")
Future.successful {
Ok(s"Uploaded Successfully, Data Length ${request.body}")
}
}
private def uploadDataBodyParser: BodyParser[Long] = BodyParser("Length Sum Parser") { request =>
Iteratee.fold[Array[Byte], Long](0) { (state, data) =>
println("SUM: " + state)
state + data.length
}.map(x => Right(x))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment