在heroku上使用s3存储选项时访问回形针temp文件

问题描述:

我正在使用Paperclip gem来调整上传照片的大小并将它们存储在亚马逊S3上。在上传请求的生命周期中,我需要访问调整大小的照片以传递给另一个Web服务。在heroku上使用s3存储选项时访问回形针temp文件

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

根据Paperclip readme有几个回调,它在处理之前和之后调用。

对于每个附件:

  • before_post_process
  • after_post_process

仅用于一个特定附着

  • before_ [附件] _post_process
  • after_ [附件] _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 
+1

谢谢Matt,这看起来就像我在找的东西。我缝合的部分缺少的是queued_for_write方法。我明天再试一试,然后回报。 – 2010-10-14 21:38:13

+0

完美工作。谢谢! – 2010-10-18 23:53:56