【问题标题】:File upload fail when in production on tomcat7在tomcat7上生产时文件上传失败
【发布时间】:2013-07-11 05:18:17
【问题描述】:

我正在使用带有 Scala 的 Play 2.1.1,并且有一个控制器来处理文件上传,特别是图像。这在本地工作得很好,但是,我现在已经使用 play2-war-plugin (https://github.com/dlecan/play2-war-plugin) 将一个 war 文件部署到运行 ubuntu 和 tomcat7 的服务器上。

现在当我上传图片时出现以下异常

[ScalaIOException: MainException: class java.io.IOException(没有这样的 文件或目录)]

我的控制器是

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"
            )
          }
    }}
}

任何建议将不胜感激。

提前致谢。

【问题讨论】:

    标签: java scala playframework playframework-2.0


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复。是的,错误就在那条线上。我无法访问该文件,因为它从未上传过。我可以访问我在本地测试时上传的那个文件夹中的文件。要访问这些文件,我只使用“/assets/upload....” url,因为在路由中我有 codeGET /assets/*file controllers.Assets.at(path="/public", file)code
    猜你喜欢
    • 2016-03-05
    • 1970-01-01
    • 2022-08-17
    • 2018-10-13
    • 2015-03-17
    • 1970-01-01
    • 2013-06-09
    • 2012-03-18
    相关资源
    最近更新 更多