I have gone through the railscast and researched here on Stack Overflow. Although I have found others with the same issue, it doesn’t appear that any of the other solutions I have researched seem to work. I have tried multiple variations of the code as suggested in other posts… No luck.
I am attempting to upload and store PDF files to Amazon S3 via the Carrierwave and Fog gems to no avail. While I am using Heroku in production, I have not attempted to deploy this to Heroku yet since I cannot even get this to work locally. The error returned is
Missing required arguments: aws_access_key_id, aws_secret_access_key
How can I fix this problem?
carrierwave.rb (initializer)
CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['MY_KEY_ID'],
aws_secret_access_key: ENV['MY_KEY']
}
config.fog_directory = ENV['MY_BUCKET']
config.fog_public = false
end
pdf_uploader.rb:
class PdfUploader < CarrierWave::Uploader::Base
storage :fog
include CarrierWave::MimeTypes
process :set_content_type
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
It looks like there was an issue with setting the key_id, key AND bucket as environmental variables. Once I changed all three to string constants, it seemed to work fine. I also deployed to Heroku and verified functionality in production as well.
the final initializer file: