未找到Scala amazon S3文件上传显示错误

时间:2016-02-21 06:11:13

标签: scala amazon-s3 playframework playframework-2.0

我正在使用playframework 2.4.6并尝试将文件上传到我的S3存储桶但是我在编译时遇到错误:Not Found value s3。我基本上试图复制本教程https://github.com/Kaliber/play-s3以及这篇类似的帖子 Play! Upload file and save to AWS S3。我的信息如下:

Build.SBT

val appDependencies = Seq(
  "net.kaliber" %% "play-s3" % "7.0.1",
   "net.kaliber" %% "play-s3" % "7.0.2"

)

Application.conf

aws.accessKeyId="akey"
aws.secretKey="skey"

然后我的控制器

  def upload=  Action.async(parse.multipartFormData) {implicit request =>
    request.body.file("file").map { file =>
     // implicit val credential = AwsCredentials.fromConfiguration
      val byteArray = Files.readAllBytes(Paths.get(file.ref.file.getPath))

      val bucket = S3("myBuckets")
    val result = bucket + BucketFile(file.filename, file.contentType.get, byteArray, None, None)
      result.map { unit =>
        Ok("File uploaded")
      }.getOrElse {
        Redirect(routes.Application.index).flashing(
          "error" -> "Missing file"
        )
      }
    }
  }

我在 val bucket = S3(“myBuckets”)上收到错误,如前所述,未找到值S3并且构建崩溃。我不知道我是否可能错过导入,因为我的IDE没有指出它...这是我对控制器的导入:

import play.api.data.Form
import play.api.libs.json.{Json, JsValue}
import play.api.mvc.{Action, Controller}
import play.mvc.Result
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import java.io.File

1 个答案:

答案 0 :(得分:0)

尝试导入:

 Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

或者如果你想具体:

    Odzież, Obuwie, Dodatki