在上传到 S3 之前访问 Paperclip 图像 [英] Access Paperclip image before it's uploaded to S3
本文介绍了在上传到 S3 之前访问 Paperclip 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
My Rails 应用程序使用 Paperclip 将图像上传到 S3.我想在将图像发送到 S3 之前拦截"它,将其转换为 base64,然后将其发送给第三方 API.
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.
如何在 Paperclip 上传到 S3 之前访问图像?这比之后从 S3 读取文件,然后将其发送到第三方 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.
推荐答案
试试这个
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
这篇关于在上传到 S3 之前访问 Paperclip 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文