【问题标题】:Play framework file upload and CSRF still not working播放框架文件上传和 CSRF 仍然无法正常工作
【发布时间】:2020-05-10 16:29:49
【问题描述】:

我正在尝试使播放文件上传示例工作:https://github.com/playframework/play-scala-fileupload-example/tree/2.6.x

但我一按“上传文件”按钮就会收到错误消息: [警告] p.filters.CSRF - [CSRF] 检查失败,因为在 /upload 的正文中没有或无效的令牌 [warn] p.filters.CSRF - [CSRF] Check failed with NoTokenInBody for /upload

浏览器告诉我:“未经授权 您必须通过身份验证才能访问此页面。”

我读过这个:https://groups.google.com/forum/#!topic/play-framework/lH5AOS2szU8

所以问题应该得到解决并且测试通过了,所以我被卡住了。 帮忙?

【问题讨论】:

    标签: scala playframework


    【解决方案1】:

    我做了一个简单的项目,可以帮助你解决这个问题。

    scalaVersion = "2.12.6"
    playVersion = "2.6.19"
    

    访问:https://github.com/rexardiente/Scala-Play-Traning

    【讨论】:

    • 这将简单地解决问题.. @helper.form(action = CSRF(routes.HomeController.upload), 'enctype -> "multipart/form-data") { <input type="file" name="picture"> <input type="submit" id="upload" value="upload file"/> }
    • 谢谢。有用。由于编译错误(例如 form 被定义了两次),我不得不稍微更改它。它看起来像这样:```` @import helper.CSRF @main("Welcome to Play") { @helper.form(action = CSRF(routes.HomeController.upload), 'enctype -> "multipart/form-data ") { @helper.inputFile(form("name")) } } ````
    • 欢迎您,很高兴为您提供帮助。
    【解决方案2】:

    它有效。谢谢。 我只是有一个错误说form 被定义了两次,所以我将导入更改为:

    @import helper.CSRF
    
    

    【讨论】:

      【解决方案3】:

      增加application.conf 中的文件大小限制对我有用:

      play.http.parser.maxMemoryBuffer=1024k
      

      将 1024k 更改为您喜欢的大小限制。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-18
        • 2017-06-14
        • 1970-01-01
        • 2019-01-04
        • 1970-01-01
        • 2018-06-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多