【问题标题】:Access Paperclip image before it's uploaded to S3在上传到 S3 之前访问回形针图像
【发布时间】:2016-07-20 13:12:23
【问题描述】:

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

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

【问题讨论】:

  • 嘿,在使用 Roman 的答案访问文件后,您最终是如何执行实际转换的?

标签: ruby-on-rails ruby paperclip


【解决方案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

【讨论】:

  • 知道如何在 Paperclip 将其写入 S3 之前使用 Prawn 将此文件转换为 PDF 吗?
猜你喜欢
  • 2014-09-09
  • 1970-01-01
  • 2013-09-09
  • 2013-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-04
  • 2012-07-07
相关资源
最近更新 更多