Access Paperclip image before it's uploaded to S3

谁说胖子不能爱 提交于 2019-12-08 04:37:48

问题


My Rails app uploads images to S3 with Paperclip. I want to "intercept" the image before it is sent to S3, convert it to base64, and send it to a third-party API.

How can I access the image before it gets uploaded by Paperclip to S3? This would be quicker than reading the file from S3 afterwards, and then sending it to the third-party API.


回答1:


Try this

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


来源:https://stackoverflow.com/questions/36344301/access-paperclip-image-before-its-uploaded-to-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!