I have a pretty straightforward model and attachment
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 could refactor the credentials into an initializer but I haven’t gotten this to save an attachment yet so I haven’t worried about it.
When I run the save for the object and its attachement I get:
RuntimeError in RecommendationsController#create
Missing credentials
I have poured over: Credentials missing when uploading photos with Paperclip and Amazon s3 but that didn’t resolve my issue.
I am using the following gems:
gem "paperclip"
gem "sws-sdk"
gem 'aws-s3'
Any other ideas?
You need to set your environment variables. Here’s two different ways to do it:
Every time you run
rails serveror any other command that accesses your S3 account you need to include your keys:I’m assuming you’re using bash so edit your
~/.bash_rcor~/.bash_profileto set your environment variablesThen open a new terminal window and double-check that they’re set
If you’re deploying to Heroku then you’ll want to provide your environment variables there as well:
You can review your Heroku config:
It will list out all of the config variables you have for that app.
You’ll probably want to put your S3 bucket name in an ENV setting as well so you don’t mess up your bucket when testing locally.