加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala播放框架文件上传错误

发布时间:2020-12-16 18:55:00 所属栏目:安全 来源:网络整理
导读:我正在使用 this教程在我的play框架应用程序中上传文件.我使用完全相同的代码,但我得到以下错误. [IOException: Path(/Users/hrishikeshparanjape/Desktop) exists but replace parameter is false] 以下是我的代码: def upload = Action(parse.multipartFo
我正在使用 this教程在我的play框架应用程序中上传文件.我使用完全相同的代码,但我得到以下错误.

[IOException: Path(/Users/hrishikeshparanjape/Desktop) exists but replace parameter is false]

以下是我的代码:

def upload = Action(parse.multipartFormData) { request =>
        request.body.file("picture").map { picture =>
            import java.io.File
            val filename = picture.filename 
            val contentType = picture.contentType
            picture.ref.moveTo(new File("/Users/hrishikeshparanjape/Desktop/"))
            Ok("File uploaded")
        }.getOrElse {
            Redirect(routes.Application.index).flashing(
                    "error" -> "Missing file"
                    )
        }
    }

我被困在这里请帮助.

编辑:
这是我的完整堆栈跟踪:

play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[IOException: Path(/Users/hrishikeshparanjape/Desktop) exists but replace parameter is false]]
    at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.2]
    at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.2]
    at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
    at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.2]
    at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2]
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2]
Caused by: java.io.IOException: Path(/Users/hrishikeshparanjape/Desktop) exists but replace parameter is false
    at scalax.file.Path$.fail(Path.scala:168) ~[scala-io-file_2.9.1.jar:0.4.0]
    at scalax.file.Path.moveTo(Path.scala:1089) ~[scala-io-file_2.9.1.jar:0.4.0]
    at play.api.libs.Files$.moveFile(Files.scala:76) ~[play_2.9.1.jar:2.0.2]
    at play.api.libs.Files$TemporaryFile.moveTo(Files.scala:30) ~[play_2.9.1.jar:2.0.2]
    at controllers.Application$$anonfun$upload$1$$anonfun$apply$1.apply(Application.scala:17) ~[classes/:2.0.2]
    at controllers.Application$$anonfun$upload$1$$anonfun$apply$1.apply(Application.scala:13) ~[classes/:2.0.2]
[info] Compiling 1 Scala source to /Users/hrishikeshparanjape/git-public/printit/target/scala-2.9.1/classes...

解决方法

看起来您需要为moveTo指定完整的文件名

picture.ref.moveTo(new File(
  "/Users/hrishikeshparanjape/Desktop/" + picture.filename))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读