Rails ActiveStorage Error - MessageVerifier-InvalidSignature

只谈情不闲聊 提交于 2019-12-05 08:14:21

Make sure to add multipart: true in form_tag. It generates enctype="multipart/form-data".

form_tag by default not responsible for it, must have it (if attaching a file).

multipart/form-data No characters are encoded. This value is required when you are using forms that have a file upload control

Form:

<%= form_tag attach_photo_location_path(@location), method: :put, multipart: true do %>
  <%= label_tag :photo %>
  <%= file_field_tag :photo %>

  <%= submit_tag "Upload" %>
<% end %>

Also:

Change post to put method, We are updating not creating Idempotency

resources :locations do
  member do
    put :attach_photo
  end
end

You need to assign the signature (in params[:signed_blob_id]) to the instance as the example from the docs illustrates.

So, like this:

@location.photos.attach(params[:signed_blob_id]) # Signed reference to blob from direct upload
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!