-
-
Save mielientiev/38fec15428e8cd0b6713 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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