0
votes

I am trying to get my image upload work with S3 but when I create config/initializers/carrierwave.rb

and add

CarrierWave.configure do |config|                                                                                                                                                                                 
  config.fog_credentials = {                                                                                                                                                                                      
    # Configuration for Amazon S3 should be made available through an Environment variable.                                                                                                                       
    # For local installations, export the env variable through the shell OR                                                                                                                                       
    # if using Passenger, set an Apache environment variable.                                                                                                                                                     
    #                                                                                                                                                                                                             
    # In Heroku, follow http://devcenter.heroku.com/articles/config-vars                                                                                                                                          
    #                                                                                                                                                                                                             
    # $ heroku config:add S3_KEY=your_s3_access_key S3_SECRET=your_s3_secret S3_REGION=eu-west-1 S3_ASSET_URL=http://assets.example.com/ S3_BUCKET_NAME=s3_bucket/folder                                          

    # Configuration for Amazon S3                                                                                                                                                                                 
    :provider              => 'AWS',                                                                                                                                                                              
    :aws_access_key_id     => ENV['S3_KEY'],                                                                                                                                                                      
    :aws_secret_access_key => ENV['S3_SECRET'],                                                                                                                                                                   
    #region                => ENV['S3_REGION']                                                                                                                                                                    
  }                                                                                                                                                                                                               

  # For testing, upload files to local `tmp` folder.                                                                                                                                                              
  #if Rails.env.test? || Rails.env.cucumber?                                                                                                                                                                      
  #  config.storage = :file                                                                                                                                                                                       
  #  config.enable_processing = false                                                                                                                                                                             
  #  config.root = "#{Rails.root}/tmp"                                                                                                                                                                            
  #else                                                                                                                                                                                                           
  #  config.storage = :fog                                                                                                                                                                                        
  #end                                                                                                                                                                                                            

  # To let CarrierWave work on heroku                                                                                                                                                                             
  config.cache_dir = "#{Rails.root}/tmp/uploads"                                                                                                                                                                  
  config.fog_directory    = ENV['S3_BUCKET_NAME']                                                                                                                                                                 

  # Generate http:// urls. Defaults to :authenticated_read (https://)                                                                                                                                             
  #config.s3_access_policy = :public_read                                                                                                                                                                         
  #config.fog_host         = "#{ENV['S3_ASSET_URL']}/#{ENV['S3_BUCKET_NAME']}"                                                                                                                                    
end                                                                                                                                                                                                               

rails s doesn't even start

I get bunch of errors like so..

=> Booting WEBrick                                                                                                                                                                                                
=> Rails 4.2.0 application starting in development on http://localhost:3000                                                                                                                                       
=> Run `rails server -h` for more startup options                                                                                                                                                                 
=> Ctrl-C to shutdown server                                                                                                                                                                                      
Exiting 

from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in each' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in block in ' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in instance_exec' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in run' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in block in run_initializers' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:226:inblock in tsort_each' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:348:in block (2 levels) in each_strongly_connected_component' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:418:inblock (2 levels) in each_strongly_connected_component_from' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:427:in each_strongly_connected_component_from' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:417:inblock in each_strongly_connected_component_from' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in each' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in tsort_each_child' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:411:in call' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:411:in each_strongly_connected_component_from' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:347:in block in each_strongly_connected_component' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:345:ineach' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:345:in call' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:345:in each_strongly_connected_component' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:224:in tsort_each' from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/tsort.rb:205:in tsort_each' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in run_initializers' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/application.rb:352:in initialize!' from /Users/atoder/Sites/rails_projects/post_app/config/environment.rb:5:in <top (required)>' from /Users/atoder/Sites/rails_projects/post_app/config.ru:3:inrequire' from /Users/atoder/Sites/rails_projects/post_app/config.ru:3:in block in <main>' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in instance_eval' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in initialize' from /Users/atoder/Sites/rails_projects/post_app/config.ru:innew' from /Users/atoder/Sites/rails_projects/post_app/config.ru:in <main>' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in eval' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in new_from_string' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:40:in parse_file' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/server.rb:299:in build_app_and_options_from_config' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/server.rb:208:in app' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/server.rb:61:in app' from /usr/local/lib/ruby/gems/2.1.0/gems/rack-1.6.0/lib/rack/server.rb:336:in wrapped_app' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/server.rb:139:in log_to_stdout' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/server.rb:78:in start' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:80:in block in server' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in tap' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in server' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in run_command!' from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in <top (required)>' from /Users/atoder/Sites/rails_projects/post_app/bin/rails:8:inrequire' from /Users/atoder/Sites/rails_projects/post_app/bin/rails:8:in <top (required)>' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/client/rails.rb:27:in load' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/client/rails.rb:27:in call' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/client/command.rb:7:in call' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/client.rb:26:in run' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/bin/spring:48:in ' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/binstub.rb:11:in load' from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.2.0/lib/spring/binstub.rb:11:in ' from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in require' from /Users/atoder/Sites/rails_projects/post_app/bin/spring:16:in `'

1
Are S3_KEY, S3_SECRET, and S3_BUCKET_NAME set?Ken Stipek
@KenStipek yep.. I have them set for heroku and also in my application.yml fileCodeCrack
So you if you open up the rails console and run puts env['S3_KEY'] it spits out the key?Ken Stipek
Not it's giving me an error when I do that as wellCodeCrack

1 Answers

1
votes

Ok I figured out the problem... the settings from application.yml were not getting loaded.. I fixed it by adding this to application.rb

if File.exists?(File.expand_path('../application.yml', __FILE__))
  ENV.update YAML.load(File.read(File.expand_path('../application.yml', __FILE__))) 
end