0

I'm using Play 2.1.1 with Scala and have a controller to deal with file uploads, specifically images. Locally this works perfectly, however, I have now deployed a war file using play2-war-plugin (https://github.com/dlecan/play2-war-plugin) to a server running ubuntu and tomcat7.

Now when I upload an image I get the following exception

[ScalaIOException: MainException: class java.io.IOException(No such file or directory)]

My controller is

def addProjectImage(id: Long) = Action(parse.multipartFormData) { implicit request =>
    DB.withSession{ implicit session => {
        request.body.file("img").map { picture =>
            import java.io.File
            val filename = picture.filename + ".png"
            val contentType = picture.contentType
            var f = new File(s"./public/upload/project_picture/${filename}")
            picture.ref.moveTo(f)
            Projects.updateImage(id, "/assets/upload/project_picture/"+filename)
            Redirect(routes.Admin.index)
          }.getOrElse {
            Redirect(routes.Application.index).flashing(
              "error" -> "Missing image"
            )
          }
    }}
}

Any suggestions would be really appreciated.

Thanks in advance.

4

1 回答 1

0

文件位置的 url 看起来确实有问题。如果您在本地没有遇到问题,但在使用 Tomcat 时遇到了问题,则应确保您编写的 url 正确。您可以使用浏览器访问它吗?您在哪一行得到 IOException?是否在var f = new File(s"./p....

于 2013-07-10T21:18:17.897 回答