1
所以我试图实现文件访问限制。 例如,获取 “flowers.jpg” 当URL看起来是这样的:... /静态/上传/ zfds98ys/flowers.jpg路由到静态时出错 - 播放框架
路线文件:
GET /static/uploads/*hashCode/*fileName controllers.Application.staticAccess(hashCode: String, fileName: String)
传递函数:
def staticAccess(hashCode: String, fileName: String) = Action { implicit request =>
if (true /*insert hash check here...*/) Redirect(routes.Assets.at("/public/uploads", fileName))
else Redirect(routes.Application.notFound())
}
即时得到这个错误:
Execution exception
[MatchError: (/public/uploads,flowers.jpg) (of class scala.Tuple2)]
123 // @LINE:12
124 def at(path:String, file:String): Call = {
125 (path: @unchecked, file: @unchecked) match {
126 // @LINE:12
127 case (path, file) if path == "/public/javascripts" =>
128 implicit val _rrc = new ReverseRouteContext(Map(("path", "/public/javascripts")))
129 Call("GET", _prefix + { _defaultPrefix } + "static/javascripts/" + implicitly[PathBindable[String]].unbind("file", file))Execution exception
为什么会这样......? 图像存在于给定路径中。那我取代了代码工作的罚款(如下图):
GET /static/uploads/*fileName controllers.Assets.at(path="/public/uploads", fileName)
你从你的'routes'文件中删除正常'Assets'路线? –
是的。我认为问题是'重定向(routes.Assets.at(“/ public/uploads”,fileName))'不够用(需要声明一个路由)。我决定现在用另一种方法 – user3723987
对。当路由不存在时,您不能使用反向路由重定向。 –