问题
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