Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to paperclip temp file when using s3 storage option on heroku

I am using the Paperclip gem to resize upload photos and store them on amazon S3. I need access to the resized photo to also pass along to another web service, during the lifecycle of the upload request.

I suspect there is a temp file created somewhere the imagemagik uses before the photo is uploaded to s3. How can I get access to it.

like image 788
Brad The App Guy Avatar asked Oct 14 '10 10:10

Brad The App Guy


1 Answers

According to Paperclip readme there're a few callbacks that it calls after and before processing.

For each attachment:

  • before_post_process
  • after_post_process

Only for a specific attachment:

  • before_[attachment]_post_process
  • after_[attachment]_post_process

I think in your case you should use one of the after callbacks to get the resized photo. Then you should be able to access the file with queued_for_write. For example:

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
like image 157
Matt Avatar answered Nov 15 '22 20:11

Matt