ChrisZou

使用 Vue 前端、Rails 后端实现图片上传的功能

  •  
  •   ChrisZou · Nov 19, 2020 · 8296 views
    This topic created in 2002 days ago, the information mentioned may be changed or developed.

    正文见 https://chriszou.com/2020/11/16/upload-image-using-vue-and-rails/
    核心方法是使用 formData 作为 ajax 的 body,之前主要不清楚的点在于 csrf token 的传递。
    当然,这里的方法可能不是最好的。如果哪位大神有更好的方法实现,还请不吝指教!

    1 replies    2020-11-25 22:33:03 +08:00
    wangkun025
        1
    wangkun025  
       Nov 25, 2020
    看的一脸懵,api 的情况下,是不需要 csrf token 的,因为没有意义。
    所以应该跳过 csrf
    方法也很简单。在 application_controller.rb 里面,修改 protect_from_forgery
    把 protect_from_forgery with: :exception 修改成 protect_from_forgery with: :null_session
    实际上,文件里有注释。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6129 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 95ms · UTC 06:12 · PVG 14:12 · LAX 23:12 · JFK 02:12
    ♥ Do have faith in what you're doing.