在上传到 S3 之前访问回形针图像

Access Paperclip image before it's uploaded to S3

我的 Rails 应用程序使用 Paperclip 将图像上传到 S3。我想"intercept"将图片发送到S3之前,转成base64,再发送给第三方API。

如何在 Paperclip 将图像上传到 S3 之前访问图像?这比之后从 S3 读取文件,然后将其发送给第三方 API.

更快

试试这个

class Model < ActiveRecord::Base

  has_attached_file :image

  before_save :send_image

  private

  def send_image
    image.queued_for_write[:original] # <= this is your image
  end
end