How to resolve "Missing Credentials" with Paperclip and s3 store in rails 3
I have a fairly simple model and application
has_attached_file :upload,
:storage => :s3,
:bucket => 'bestofbauer',
:s3_credentials => {
:access_key_id => ENV['MyAccessKEY'],
:secret_access_key => ENV['MySecretKey']
}
I have a bucket setup with s3 called bestofbauer.
I know I can refactor the credentials into the initializer, but I didn't get that to keep the attachment, but so I didn't bother with that.
When I run save the object and attach it, I get:
RuntimeError in RecommendationsController#create
Missing credentials
I poured out: Invalid credentials when uploading photos with Paperclip and Amazon s3 , but that didn't solve my problem.
I use the following gems:
gem "paperclip"
gem "sws-sdk"
gem 'aws-s3'
Any other ideas?
source to share
You need to set environment variables. Here are two different ways to do it:
-
Every time you run
rails server
or any other command that accesses your S3 account, you need to enable your keys:$ MyAccessKEY=ACCESS_KEY MySecretKEY=SECRET_KEY rails server
-
I am assuming you are using bash, so edit your
~/.bash_rc
or~/.bash_profile
to set environment variablesexport MyAccessKEY=ACCESS_KEY export MySecretKEY=SECRET_KEY
Then open a new terminal window and double check that they are installed
$ echo $MyAccessKey > ACCESS KEY PRINTS OUT HERE
If you are deploying to Heroku, you will also need environment variables:
$ heroku config:add MyAccessKEY=ACCESS_KEY MySecretKEY=SECRET_KEY
You can view Heroku config:
$ heroku config
It will list all the configuration options you have for this application.
You probably want to put your S3 bucket name in the ENV setting so you don't mess up your bucket when testing locally.
source to share