views:

38

answers:

1

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.

+1  A: 

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
Matt
Thanks Matt, this looks like what I was looking for. The piece I seamed to be missing was the queued_for_write method. I'll give it a shot tomorrow and report back.
Brad Smith
Worked Perfectly. Thanks!
Brad Smith