本文整理汇总了Scala中play.api.mvc.BodyParser类的典型用法代码示例。如果您正苦于以下问题:Scala BodyParser类的具体用法?Scala BodyParser怎么用?Scala BodyParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BodyParser类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Utility
//设置package包名称以及导入依赖的类
package controllers
import play.api.Play
import play.api.mvc.{BodyParser, MultipartFormData, RequestHeader}
import play.core.parsers.Multipart
object Utility {
import play.api.mvc.BodyParsers.parse._
def multipartFormData[A](filePartHandler: RequestHeader => Multipart.FilePartHandler[A], maxLength: Long = DefaultMaxDiskLength): BodyParser[MultipartFormData[A]] = {
BodyParser("multipartFormData") { request =>
val app = play.api.Play.current // throw exception
implicit val mat = app.materializer
val bodyAccumulator = Multipart.multipartParser(DefaultMaxTextLength, filePartHandler(request)).apply(request)
// TODO enforceMaxLength(request, maxLength, bodyAccumulator) or maybe not
bodyAccumulator
}
}
}
示例2: Auth
//设置package包名称以及导入依赖的类
package utils.auth.deadbolt
import javax.inject.{Inject, Singleton}
import be.objectify.deadbolt.scala.DeadboltActions
import com.mohiva.play.silhouette.api.Silhouette
import models.Roles
import play.api.mvc.{BodyParser, BodyParsers, Result, Results}
import utils.auth.DefaultEnv
import scala.concurrent.Future
@Singleton
class Auth @Inject()(deadboltActions: DeadboltActions, silhouette: Silhouette[DefaultEnv])
extends Results with BodyParsers {
def SubjectPresent[B](parser: BodyParser[B] = parse.anyContent)(block: SecureRequest[B] => Future[Result]) =
silhouette.SecuredAction.async(parser) { implicit req =>
deadboltActions.SubjectPresent()(parser)(block.compose(_ => new SecureRequest(req)))(req)
}
def Restrict[B](parser: BodyParser[B] = parse.anyContent)(role: Roles.Role)(block: SecureRequest[B] => Future[Result]) =
silhouette.SecuredAction.async(parser) { implicit request =>
deadboltActions.Restrict(role.group)(parser)(block.compose(_ => new SecureRequest(request)))(request)
}
}