0
votes

I am trying to use paperclip with S3 AWS. I have set the secret keys and bucket name in the .bash_profile but Rials/Paperclip cannot seem to read them as i get the following error when i try to upload an image in development...

'missing required :bucket option'

If i replace the ENV['S3_BUCKET_NAME'] with the actual name, i then get the following...

'Missing Credentials. Unable to find AWS credentials'

Here is the set-up in the model...

has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :s3,
:s3_credentials => {
  :bucket => ENV['S3_BUCKET_NAME'],
  :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
  :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
        },
:s3_host_name => 's3-eu-west-1.amazonaws.com'

I have tried putting the credentials in the development config file in Rails but i have the same errors. Do i need to tell rails where to look for the ENV variables or am I doing something else wrong here? It seems others are having similar issues but i cannot find a solution.

Thanks for reading.

1

1 Answers

0
votes

Just store the AWS bucket, key and key_id in a YAML file and in 'config/initializers', create a new file to read the YAML file contents and set the corresponding ENV variables. Don't forget to restart your rails server

Example

google_client =  YAML.load_file("#{Rails.root.join('config/google_client.yml')}")
ENV['GOOGLE_APP_NAME'] = google_client['APP_NAME']
ENV['GOOGLE_CLIENT_ID'] = google_client['CLIENT_ID']
ENV['GOOGLE_CLIENT_SECRET'] = google_client['CLIENT_SECRET']
ENV['GOOGLE_CLIENT_SCOPE'] = google_client['CLIENT_SCOPE']

Typically, we do not push the aws info in Github commit but just ssh to the remote server and place the YAML file in the config folder in our Rails app. So only people who have access to your server can read your aws credentials and not all people even if they have Github access.

tell me if this solves your problem.