All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.boilerplate.api.server.dsl.Compat.scala Maven / Gradle / Ivy

The newest version!
package play.boilerplate.api.server.dsl

import play.api.http.Writeable
import play.api.mvc.AnyContent

object Compat extends AbstractCompat {

  implicit class AnyContentOps(val body: AnyContent) extends AnyVal {

    def dataPart(key: String): Option[String] = {
      body.asMultipartFormData.flatMap(_.dataParts.get(key)).flatMap(_.headOption)
    }

    def file(key: String): Option[java.io.File] = {
      body.asMultipartFormData.flatMap(_.file(key)).map(_.ref.path.toFile)
    }

    def formValue(key: String): Option[String] = {
      body.asFormUrlEncoded.flatMap(_.get(key)).flatMap(_.headOption)
    }

  }

  implicit def contentOps[C](implicit wr: Writeable[C]): PrintableContent[C] =
    PrintableContent(content => wr.transform(content).utf8String)

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy