在将Paperclip图像上传到S3之前访问它

时间:2016-03-31 21:37:25

标签: ruby-on-rails ruby paperclip

My Rails应用程序使用Paperclip将图像上传到S3。我希望在将图像发送到S3之前“拦截”图像,将其转换为base64,然后将其发送到第三方API。

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

1 个答案:

答案 0 :(得分:1)

试试这个

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