本文整理汇总了Scala中play.api.libs.Files类的典型用法代码示例。如果您正苦于以下问题:Scala Files类的具体用法?Scala Files怎么用?Scala Files使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Files类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: UploadZipRecipeForm
//设置package包名称以及导入依赖的类
package requests
import models.Password
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import play.api.libs.Files
import play.api.mvc.{MultipartFormData, Request}
case class UploadZipRecipeForm(
version: String,
password: String,
file: MultipartFormData.FilePart[Files.TemporaryFile]
) {
def passwordRecord = {
Password(0L, version, MyBCrypt.createHash(password))
}
}
object UploadZipRecipeForm {
def fromReq(req: Request[MultipartFormData[Files.TemporaryFile]]): Option[UploadZipRecipeForm] = {
val data = req.body.dataParts
for {
version <- data.get("ver").flatMap(_.headOption)
password <- data.get("password").flatMap(_.headOption)
file <- req.body.file("zipFile")
} yield new UploadZipRecipeForm(version, password, file)
}
}
object MyBCrypt {
val bcrypt = new BCryptPasswordEncoder(12)
def createHash(password: String) = bcrypt.encode(password)
def authenticate(password: String, hash: String): Boolean =
bcrypt.matches(password, hash)
}
开发者ID:ponkotuy,项目名称:FactorioRecipe,代码行数:35,代码来源:UploadZipRecipeForm.scala
示例2: CameraRelayControllerTest
//设置package包名称以及导入依赖的类
package controllers
import com.intersection.camerarelay.UploadManager
import org.mockito.Matchers._
import org.scalatest.concurrent.{Futures, ScalaFutures}
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{BeforeAndAfter, FunSpec, Matchers}
import play.api.libs.Files
import play.api.mvc.{Request, Result}
import play.api.test.FakeRequest
import play.api.test.Helpers._
import org.mockito.Mockito._
import scala.concurrent.Future
class CameraRelayControllerTest extends FunSpec with Matchers with MockitoSugar with BeforeAndAfter with Futures with ScalaFutures {
var controller : CameraRelayController = _
var uploadManager : UploadManager = _
before {
uploadManager = mock[UploadManager]
controller = new CameraRelayController(uploadManager)
}
describe(classOf[CameraRelayControllerTest].getName) {
it("Rejects requests without a valid siteId header : X-Site-Id") {
val request: Request[Files.TemporaryFile] = FakeRequest().withHeaders(("Content-Type"->"application/octet-stream"), ("X-Link-Time"->"2016-12-12")).withBody(Files.TemporaryFile())
val result = controller.uploadVideoChunk().apply(request)
status(result) should equal(400)
}
it("Rejects requests without a valid Link-Time header : X-Link-Time") {
val request: Request[Files.TemporaryFile] = FakeRequest().withHeaders(("Content-Type"->"application/octet-stream"), ("X-Site-Id"->"mn-1234")).withBody(Files.TemporaryFile())
val result: Future[Result] = controller.uploadVideoChunk().apply(request)
status(result) should equal(400)
}
it("Accepts a fully formed request") {
import scala.concurrent.ExecutionContext.Implicits.global
when(uploadManager.handleVideoChunk(any[String],any[String],any[Files.TemporaryFile])).thenReturn(Future(()))
val request: Request[Files.TemporaryFile] = FakeRequest().withHeaders(("Content-Type"->"application/octet-stream"), ("X-Site-Id"->"mn-1234"), ("X-Link-Time"->"2016-12-12")).withBody(Files.TemporaryFile())
val result: Future[Result] = controller.uploadVideoChunk().apply(request)
status(result) should equal(202)
}
}
}
开发者ID:arjunmukherjee,项目名称:camerarelay,代码行数:48,代码来源:CameraRelayControllerTest.scala
示例3: ExtractFile
//设置package包名称以及导入依赖的类
package models
import java.io.File
import com.github.pochi.runner.scripts.{ScriptRunner, ScriptRunnerBuilder}
import play.api.libs.Files
import play.api.mvc.{MultipartFormData, Request}
import services.Extracter
class ExtractFile(request: Request[MultipartFormData[Files.TemporaryFile]], kindOfBirthmark: Birthmark) {
val result = request.body.file("file").map { file =>
val filename = file.filename
val contentType = file.contentType
file.ref.moveTo(new File("files", filename))
// filename, kindOfBirthmark
// new Extracter().getExtractFile("files/" + file.filename, kindOfBirthmark.birthmark)
def getExtractFile: String ={
val builder: ScriptRunnerBuilder = new ScriptRunnerBuilder
val runner: ScriptRunner = builder.build
val arg: Array[String] = Array("./extract.js", "files/" + file.filename, kindOfBirthmark.birthmark)
runner.runsScript(arg)
file.filename + ".csv"
}
getExtractFile
}
val extractFile = result.get
println(result.get)
}
开发者ID:mitubaEX,项目名称:InMITU,代码行数:30,代码来源:ExtractFile.scala
示例4: ExtractFile
//设置package包名称以及导入依赖的类
package models
import java.io.File
import com.github.pochi.runner.scripts.{ScriptRunner, ScriptRunnerBuilder}
import play.api.libs.Files
import play.api.mvc.{MultipartFormData, Request}
import services.Extracter
class ExtractFile(request: Request[MultipartFormData[Files.TemporaryFile]], kindOfBirthmark: Birthmark) {
val result = request.body.file("file").map { file =>
val filename = file.filename
val contentType = file.contentType
file.ref.moveTo(new File("files", filename))
// filename, kindOfBirthmark
// new Extracter().getExtractFile("files/" + file.filename, kindOfBirthmark.birthmark)
def getExtractFile: String ={
val builder: ScriptRunnerBuilder = new ScriptRunnerBuilder
val runner: ScriptRunner = builder.build
val arg: Array[String] = Array("./extract.js", "files/" + file.filename, kindOfBirthmark.birthmark)
runner.runsScript(arg)
file.filename + ".csv"
}
getExtractFile
}
val extractFile = result.get
}
开发者ID:mitubaEX,项目名称:MITUBASearcher,代码行数:29,代码来源:ExtractFile.scala
示例5: iPostC
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import play.api.Environment
import play.api.cache.CacheApi
import play.api.db.slick.DatabaseConfigProvider
import play.api.i18n.MessagesApi
import play.api.libs.Files
import play.api.mvc._
import services.iPostService
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
@Singleton
class iPostC @Inject()(dbConfigProvider: DatabaseConfigProvider, env: Environment, cache: CacheApi, messagesApi: MessagesApi)
extends iPostService(dbConfigProvider, env, cache, messagesApi: MessagesApi) {
def index = Action.async { implicit req: Request[_] =>
getIndexViewDto.flatMap { v =>
Future successful Ok(views.html.iPostC.index(v))
}
}
def reserve: Action[MultipartFormData[Files.TemporaryFile]] = Action.async(parse.multipartFormData) { implicit req: Request[_] =>
savePost.flatMap { _ =>
Future successful Redirect(routes.iPostC.index().url)
}
}
def post = Action.async { implicit req: Request[_] =>
postToInstagram.flatMap { _ =>
Future successful Ok("")
}
}
}
开发者ID:yukihirai0505,项目名称:sns-alert,代码行数:41,代码来源:iPostC.scala
示例6: FacebookC
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.{Inject, Singleton}
import play.api.Environment
import play.api.cache.CacheApi
import play.api.db.slick.DatabaseConfigProvider
import play.api.i18n.MessagesApi
import play.api.libs.Files
import play.api.mvc.{Action, MultipartFormData, Request}
import services.FacebookService
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
@Singleton
class FacebookC @Inject()(dbConfigProvider: DatabaseConfigProvider, env: Environment, cache: CacheApi, messagesApi: MessagesApi)
extends FacebookService(dbConfigProvider, env, cache, messagesApi) {
def auth = Action.async { implicit req: Request[_] =>
Future successful Redirect(AUTH_URL(req, env))
}
def callback(code: String) = Action.async { implicit req: Request[_] =>
super.callback(code).flatMap {
case None => Future successful Redirect(routes.LoginC.login().url)
case Some(account) => Future successful Redirect(routes.MyPageC.index().url).withSession(account.session)
}
}
def remove = Action.async { implicit req: Request[_] =>
removeToken.flatMap {
case false => Future successful Redirect(routes.LoginC.login().url)
case true => Future successful Redirect(routes.MyPageC.index().url)
}
}
def post: Action[MultipartFormData[Files.TemporaryFile]] = Action.async(parse.multipartFormData) { implicit req: Request[_] =>
postMessage.flatMap {
case Right(bool) =>
if (bool) Future successful Redirect(routes.SplashC.index().url)
else Future successful Redirect(routes.LoginC.login().url)
case Left(_) => Future successful Redirect(routes.FacebookC.auth().url)
}
}
}
开发者ID:yukihirai0505,项目名称:sns-alert,代码行数:50,代码来源:FacebookC.scala
示例7: UploadServiceSpec
//设置package包名称以及导入依赖的类
package services
import scala.concurrent.Future
import org.specs2.mock.Mockito
import org.specs2.mutable._
import org.specs2.runner._
import controllers.Application
import play.api.mvc.Controller
import play.api.mvc.Results
import play.api.test._
import play.api.test.Helpers._
import org.junit.runner.RunWith
import play.api.mvc.Result
import play.api.mvc.Request
import play.api.mvc.MultipartFormData
import play.api.libs.Files.TemporaryFile
import play.api.mvc.MultipartFormData.BadPart
import play.api.mvc.MultipartFormData.MissingFilePart
import play.api.mvc.MultipartFormData.FilePart
import play.api.libs.Files
class UploadServiceSpec extends Specification with Mockito {
"UploadService" should {
"uploadFile returns (File uploaded)" in new WithApplication {
val files = Seq[FilePart[TemporaryFile]](FilePart("file", "UploadServiceSpec.scala", None, TemporaryFile("file", "spec")))
val multipartBody = MultipartFormData(Map[String, Seq[String]](), files, Seq[BadPart](), Seq[MissingFilePart]())
val fakeRequest = FakeRequest[MultipartFormData[Files.TemporaryFile]]("POST", "/", FakeHeaders(), multipartBody)
val success = UploadService.uploadFile(fakeRequest)
success must beEqualTo("File(UploadServiceSpec.scala) uploaded")
}
"uploadFile returns (Missing file)" in new WithApplication {
val files = Seq[FilePart[TemporaryFile]]()
val multipartBody = MultipartFormData(Map[String, Seq[String]](), files, Seq[BadPart](), Seq[MissingFilePart]())
val fakeRequest = FakeRequest[MultipartFormData[Files.TemporaryFile]]("POST", "/", FakeHeaders(), multipartBody)
val success = UploadService.uploadFile(fakeRequest)
success must beEqualTo("Missing file")
}
}
}
开发者ID:boris9999,项目名称:scala-aws,代码行数:43,代码来源:UploadServiceSpec.scala
示例8: WiredApiService
//设置package包名称以及导入依赖的类
package services
import java.time.OffsetDateTime
import play.api.libs.Files
import play.api.mvc.MultipartFormData
import shared.models.WiredApiModel.ApiResult
import shared.models.slick.default._
import shared.services.WiredApi
import shared.utils.Implicits
import shared.utils.LoremIpsum
class WiredApiService(user: User,
services: Services,
files: Seq[MultipartFormData.FilePart[Files.TemporaryFile]])
extends WiredApi
with Implicits {
override def ping(): ApiResult[String] = "pong".asResult
override def now(): ApiResult[OffsetDateTime] = OffsetDateTime.now.asResult
override def createLoremIpsum(): ApiResult[List[String]] = {
Thread.sleep(2000)
LoremIpsum.paragraphs(15).asResult
}
}
开发者ID:Daxten,项目名称:bay-scalajs.g8,代码行数:28,代码来源:WiredApiService.scala
示例9: fop
//设置package包名称以及导入依赖的类
package bmlogic.common.files
import java.io.File
import play.api.libs.Files
import java.io.FileInputStream
import bmutil.errorcode.ErrorCode
import play.api.mvc.MultipartFormData
import play.api.libs.Files.TemporaryFile
import play.api.libs.json.Json
import play.api.libs.json.Json._
import play.api.libs.json.JsValue
object fop {
def uploadFile(data : MultipartFormData[TemporaryFile]) : JsValue = {
data.file("upload").map { x =>
Files.TemporaryFile(x.ref.file).moveTo(new File("upload/" + x.filename), true)
Json.toJson(Map("status" -> toJson("ok"),
"file_name" -> toJson(x.filename),
"result" -> toJson("success")))
}.getOrElse {
ErrorCode.errorToJson("post image error")
}
}
def downloadFile(name : String) : Array[Byte] = {
val file = new File("upload/" + name)
val reVal : Array[Byte] = new Array[Byte](file.length.intValue)
new FileInputStream(file).read(reVal)
reVal
}
}
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:36,代码来源:fop.scala
注:本文中的play.api.libs.Files类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论