【问题标题】:Error: `No handler found` with Base64 for Paperclip 5.2错误:使用 Base64 用于 Paperclip 5.2 的“未找到处理程序”
【发布时间】:2018-03-08 14:58:37
【问题描述】:

我遇到了将图片上传为 base64 的问题。

回形针版本 5.1.0 或更低版本

一切正常

我的模特:

do_not_validate_attachment_file_type :image

has_attached_file :image

我的控制器操作:

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

我的参数:

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

升级版本后我总是得到:

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

有没有人遇到过类似的问题,可能新版本不支持base64了?

回形针版本:5.2.0 或最新

Rails 版本:5.1.4

Ruby 版本:2.3.4p301

【问题讨论】:

    标签: ruby-on-rails ruby paperclip


    【解决方案1】:

    升级后遇到类似问题,发现解决方法是在config/initializers/paperclip.rb中添加以下内容:

    Paperclip::DataUriAdapter.register
    

    看起来这发生在 5.2.0 之前

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      相关资源
      最近更新 更多