@post.images.attach sometimes raises ActiveSupport::MessageVerifier::InvalidSignature (mismatched digest)

I have this controller action:

  def attach_image
    if @post.images.attach params[:image]
      # success response
    else
      # unprocessable entity
    end
  end

And this is the code in the model:

class Post < ApplicationRecord
  has_many_attached :images do |attachable|
    attachable.variant :medium, resize_to_fit: [800, 1600]
  end
  
  validates :images, processable_image: true, content_type: ['image/png', 'image/jpeg'], size: { less_than: 10.megabytes }

The code works properly, however in production logs I find some errors like this:

ActiveSupport::MessageVerifier::InvalidSignature (mismatched digest):
  
app/controllers/posts_controller.rb:33:in `attach_image'

I cannot reproduce the issue, so I don’t know what is causing that strange exception for some uploads…

Any idea?

i have the same pb, have you find a way ?

Check if you’re receiving correct signed_id in params[:image].

ActiveStorage::Blob.find_signed! would raise this error when you’re calling @post.images.attach where params[:image] is a string containing wrong signed_id.

Check if you’re receiving correct signed_id in params[:image] .

It’s really hard to reproduce: the error appears sometimes in the logs, but I don’t know why it happens and how to reproduce it. All my attempts work successfully,…

params[:image] is a string containing wrong signed_id .

Also, I think that params[:image] contains the actual file uploaded, not a signature (I am not using direct upload to S3 from client - I am sending the file for the upload to the server and then to s3).