Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Importing Gravatars does not work in Heroku

Having finished the latest video in advanced programming of a ruby on rails application, it does not work on Heroku.

It works fine on the local machine. But the images don't import when running "heroku run rake import_avatars".

This is the log: Importing avatars from gravatar Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: identify -format %m '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: identify -format %m '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: convert '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' -auto-orient -resize "800x800>" '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v420130506-2-iu0k8' Command :: file -b --mime '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v420130506-2-iu0k8' Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: identify -format %m '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: identify -format %m '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: convert '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' -auto-orient -resize "300x200>" '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v420130506-2-bfi8ar' Command :: file -b --mime '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v420130506-2-bfi8ar' Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: identify -format %m '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: identify -format %m '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: convert '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' -auto-orient -resize "260x180>" '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v420130506-2-1ujfbko' Command :: file -b --mime '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v420130506-2-1ujfbko' Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: identify -format %m '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: identify -format %m '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' Command :: convert '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v4.jpg[0]' -auto-orient -resize "80x" -crop "80x80+0+0" +repage '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v420130506-2-1qdnjot' Command :: file -b --mime '/tmp/44037252c3442d0e9151886a52be40c420130506-2-1phh4v420130506-2-1qdnjot' [paperclip] Saving attachments.

and so on.

4 Answers

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Caitlin Intrator sorry for the trouble. By default, Paperclip doesn't work well on Heroku because you're not using a single machine to serve the files and don't really have access to the file system. So, what most people do is use Amazon S3 (http://aws.amazon.com). It's a paid service but it's really inexpensive for a lot of file storage. Here's how you use it once you sign up:

Add this to you Gemfile and bundle install:

gem 'aws-sdk'

Then open up treebook in your text editor and open up config/environments/production.rb and place the following in there:

config.paperclip_defaults = {
  :storage => :s3,
  :s3_credentials => {
    :bucket => ENV['AWS_BUCKET'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  }
}

Then you need to set the heroku variables locally:

heroku config:set AWS_BUCKET=your_bucket_name
heroku config:set AWS_ACCESS_KEY_ID=your_access_key_id
heroku config:set AWS_SECRET_ACCESS_KEY=your_secret_access_key

After that, deploy to heroku again and you should be set. Let me know if you have any more trouble!

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

Hi Caitlin Intrator,

Sorry for the slow reply. I'm not sure what the answer is here, but Jason Seifer should be able to help you out!

Nick

Works like a charm. Thanks Jason!

Todd Nestor
Todd Nestor
10,689 Points

Works for me too! I was trying to figure out why the images from my heroku app kept disappearing when I updated it, but now that I did this it works like a charm too :)