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

问题描述 投票:1回答:1

我似乎无法将文件上传到我的本地目录,将它们放置在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

我希望这是足够的信息对我有帮助,在此先感谢

PS我正在使用IntelliJ 15.0,如果有什么区别

forms scala file-upload playframework
1个回答
0
投票

看来您是从Windows计算机上运行本教程的,所以我要更改这一行:

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

对此:

picture.ref.moveTo(new File("""C:\*****\""" + picture.filename))
© www.soinside.com 2019 - 2024. All rights reserved.