Rails ActiveStorage Error - MessageVerifier-InvalidSignature Rails ActiveStorage Error - MessageVerifier-InvalidSignature ruby-on-rails ruby-on-rails

Rails ActiveStorage Error - MessageVerifier-InvalidSignature


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

enter image description here

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  endend


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


I solved this issue using this

  def user_params    params.permit(      :id, :name, :email, :username, :country, :avatar, :id_number, :license_number    ).select {|x,v| v.present?}  end

Looks like the empty value is causing the issue "avatar"=>""

 "id_number"=>"234545", "license_number"=>"234545", "avatar"=>""

My model

class User < ApplicationRecord  has_one_attached :avatar