Search code examples
ruby-on-railsrubypaperclip

Error: `No handler found` with Base64 for Paperclip 5.2


I'm facing with problem to upload images as base64.

Everything works fine with paperclip version 5.1.0 or lower

My model:

do_not_validate_attachment_file_type :image

has_attached_file :image

My controller action:

def update
  current_appointment.update(update_params)

  redirect_to check_in_flow.next_step_path
end

private

def update_params
  params.require(:appointment).permit(:image)
end

My params:

<ActionController::Parameters {"appointment"=>{"image"=>"data:image/png;base64, iVBORw0KGgo..."}, "controller"=>"my_controller", "action"=>"update"} permitted: false>

After upgrading version I'm always getting:

 Paperclip::AdapterRegistry::NoHandlerError:
   No handler found for "data:image/png;base64, iVBORw0KGgo..."

Is anyone got similar problem, maybe new version not support base64 anymore ?

Paperclip version: 5.2.0 or newest

Rails version: 5.1.4

Ruby version: 2.3.4p301


Solution

  • Ran into a similar issue after upgrading and found the solution was to add the following to config/initializers/paperclip.rb:

    Paperclip::DataUriAdapter.register
    

    Looks like this happened prior to 5.2.0

    https://github.com/thoughtbot/paperclip/pull/2435