Reputation: 1807
I am using rails 3.2.1, carrierwave 0.5.8, fog 1.1.2, rmagick 2.13.1.
I am trying to upload pictures of products onto an amazon s3, but i keep getting this error message no matter what permutation of the carrierwave.rb initializer file I find on the web (and I think I've tried them all), none seems to work. Nothing is uploaded to my S3 bucket either. I get the same error msg for the other versions I've tried. I think it may be something in my controller, but not sure what could trip it. PLEASE HELP!
error msg from heroku log:
2012-03-05T06:35:18+00:00 app[web.1]: app/controllers/products_controller.rb:40:in `update'
2012-03-05T06:35:18+00:00 app[web.1]: ArgumentError (Missing required arguments: aws_access_key_id, aws_secret_access_key):
2012-03-05T06:35:18+00:00 app[web.1]: cache: [POST /products/3] invalidate, pass
carrierwave initializer
CarrierWave.configure do |config|
if Rails.env.production?
config.storage = :fog
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'access_key',
:aws_secret_access_key => 'secret_access_key',
:region => 'us-east-1'
}
config.fog_directory = 'bucket_name'
config.fog_public = true
config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}
else
#for development and testing locally
config.storage = :file
config.enable_processing = false
end
end
image_uploader
include CarrierWave::RMagick
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb_pic do
process :resize_to_limit => [170, 170]
end
end
controller
def create
@all_categories = get_all_categories
checked_categories = get_categories_from(params[:categories])
removed_categories = @all_categories - checked_categories
@product = Product.new(params[:product])
if @product.save
checked_categories.each {|cat| @product.categories << cat if [email protected]?(cat)}
removed_categories.each {|cat| @product.categories.delete(cat) if @product.categories.include?(cat)}
redirect_to(:action => 'list')
else
render "new"
end
end
This is what I see when I checked the heroku config
DATABASE_URL => .....
GEM_PATH => vendor/bundle/ruby/1.9.1
LANG => en_US.UTF-8
PATH => bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
RACK_ENV => production
RAILS_ENV => production
S3_BUCKET => bucket_name
S3_KEY => access_key
S3_SECRET => secret_access_key
SHARED_DATABASE_URL => .....
I've spent a good two days on this already and nothing.
Upvotes: 1
Views: 2479
Reputation: 1807
There were several issues wrong with my code. I needed to change config.fog_public
to false (per Amazon) and there was an issue with the fog gem from my end. Apparently it wasn't transferring the information. I had to manually add the info via these two lines:
compute = Fog::Compute.new(:provider => 'AWS', :aws_access_key_id => ACCESS_KEY_ID, :aws_secret_access_key => SECRET_ACCESS_KEY)
and
storage = Fog::Storage.new(:provider => 'AWS', :aws_access_key_id => ACCESS_KEY_ID, :aws_secret_access_key => SECRET_ACCESS_KEY)
After that, everything worked. Also, make sure to put it in a string format because rails doesn't recognize anything starting in cap letters as a string unless made explicit.
Upvotes: 1
Reputation: 22238
Take out the if Rails.env.production?
.
If you're doing it right, you should be using environment variables to store your credentials, and you should also be matching your dev, test and productions environments in terms of functionality (Bucket name should also probably be a config var)
Upvotes: 1