0

I've been struggling with this problem for a day now and can't find anything else online to help. I have a Rails 4 application where I'm using AWS S3 and the paperclip gem to host user avatars. I've set my Heroku config variables for the bucket, access key ID, and secret key as well as the region. However, I keep getting this error in my Heroku logs whenever I try uploading a picture on the heroku app:

Aws::Errors::MissingRegionError (missing region; use :region option or export region name to ENV['AWS_REGION']):

In my production.rb file, I have this code:

app/config/environments/production.rb

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

I've followed this link closely (https://devcenter.heroku.com/articles/paperclip-s3) but still not sure why I keep getting the error. I've also tried hardcoding 'us-west-1' and that doesn't work.

In the heroku console:

irb(main):001:0> ENV['AWS_REGION']
=> "us-west-1"

Any help would be appreciated.

1 Answer 1

0

After a lot of trials, I think I solve the issue. The main changes I made were 1) using gem 'aws-sdk', '< 2.0' in the gemfile instead of v2.0. Secondly, this change in product.rb:

  config.paperclip_defaults = {
    storage: :s3,
    :s3_credentials => {
      bucket: ENV['AWS_BUCKET'],
      :s3_credentials => "#{Rails.root}/config/aws.yml",
    }
  }

and the creation of aws.yml, which aws-sdk looks for:

app/config/aws.yml

development:
  access_key_id: AWS_ACCESS_KEY_ID
  secret_access_key: AWS_SECRET_ACCESS_KEY

production:
  access_key_id: AWS_ACCESS_KEY_ID
  secret_access_key: AWS_SECRET_ACCESS_KEY

If anyone still has issues then following this link might help you: http://www.korenlc.com/rails-uploading-photos-via-amazon-s3-and-paperclip/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.