【问题标题】:Access to paperclip temp file when using s3 storage option on heroku在heroku上使用s3存储选项时访问回形针临时文件
【发布时间】:2011-04-25 08:00:19
【问题描述】:

我正在使用 Paperclip gem 来调整上传照片的大小并将它们存储在 amazon S3 上。在上传请求的生命周期内,我还需要访问调整大小的照片以传递给另一个 Web 服务。

我怀疑在将照片上传到 s3 之前,在 imagemagik 使用的某处创建了一个临时文件。我怎样才能访问它。

【问题讨论】:

    标签: ruby-on-rails amazon-s3 heroku paperclip


    【解决方案1】:

    根据Paperclip readme,它在处理前后调用了一些回调。

    对于每个附件:

    • before_post_process
    • after_post_process

    仅适用于特定附件:

    • before_[附件]_post_process
    • after_[attachment]_post_process

    我认为在您的情况下,您应该使用 after 回调之一来获取调整大小的照片。然后您应该可以使用queued_for_write 访问该文件。例如:

    class MyModel < ActiveRecord::Base
      has_attached_file :photo, :styles => { :small => "300x300>" }
      after_post_process :send_photo
    
      private
      def send_photo
        path = photo.queued_for_write[:small].path
        # upload the photo to the ws here
      end
    
    end
    

    【讨论】:

    • 谢谢马特,这看起来像我想要的。我接缝丢失的部分是 queued_for_write 方法。我明天试一试,然后报告。
    猜你喜欢
    • 1970-01-01
    • 2013-12-04
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 2015-12-31
    相关资源
    最近更新 更多