无法将文件上传到本地目录

时间:2015-12-08 14:57:21

标签: forms scala file-upload playframework

我似乎无法将文件上传到我的本地目录,将它们放在appdata / Temp目录中,但它只是临时工作,这就是为什么我要将它们上传到Temp以外的目录

我尝试过几个教程,但我似乎得到了同样的错误:

[NoSuchFileException: C:\*****\multipartBody2177348957005612751asTemporaryFile -> \*****\Knipsel.PNG]

views.html.index:

@helper.form(action = routes.Application.uploadFile, 'enctype -> "multipart/form-data") {
< input type="file" name="fileUpload">
<p>
<input type="submit" value="Upload">
</p>
}

Application.scala

 import java.io.File

 def uploadFile = Action(parse.multipartFormData) { request =>
 request.body.file("fileUpload").map { picture =>
  val Filename = picture.filename
  val contentType = picture.contentType.get
  picture.ref.moveTo(new File("/*****/" + picture.filename))
}.getOrElse {
  Redirect(routes.Application.index)
}
Ok("File has been uploaded")
}

路线:

POST    /upload                 controllers.Application.uploadFile

教程:

http://blog.knoldus.com/2013/01/22/play-framework-uploading-a-file-to-server/

https://www.playframework.com/documentation/2.4.x/ScalaFileUpload

我希望这是足够的信息来帮助我,提前谢谢

P.S。我使用IntelliJ 15.0,如果这有任何区别

1 个答案:

答案 0 :(得分:0)

您似乎从Windows计算机上运行本教程,因此我将更改该行:

picture.ref.moveTo(new File("/*****/" + picture.filename))

到此:

picture.ref.moveTo(new File("""C:\*****\""" + picture.filename))