Brad The App Guy
Brad The App Guy

Reputation: 16275

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.

Upvotes: 9

Views: 4827

Answers (1)

Matt
Matt

Reputation: 5398

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

Upvotes: 13

Related Questions