Question

Update:

it's really weird. I made a new app quickly and actually uploaded a file, but then I realized I had forgot to change storage :file to storage :fog. When I made that change to storage :fog, this new app broke github.com/MikeOnRails/s3 How could that one change break an app?

Original Question

I keep breaking and making new heroku apps trying to figure out how to get Amazon s3 to work with carrier wave.

I found some instructions on the carrier wave git hub page but maybe I'm doing something. Carrier. I added my environment variables without problem (i.e. site didn't break)

heroku config:add S3_KEY=NOTREAL8844848L S3_SECRET=NOTREAL345566

then i created a file in the initializers directory called carrierwave_s3.rb and put this code in it

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => ENV['S3_KEY'],
    :aws_secret_access_key  => ENV['S3_SECRET'],
    :region                 => 'US-Standard'
  }
  config.fog_directory  = 'm73test'
  config.fog_host       = 'https://m73test.s3.amazonaws.com'
  config.fog_public     = true
  config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}
end

I also tried putting single quotes around the ENV variables

 :aws_access_key_id      => 'ENV['S3_KEY']',
    :aws_secret_access_key  => 'ENV['S3_SECRET']',

In uploaders/image_uploader.rb

I changed

storage :file

to

storage :fog

Note, in uploaders/image_uploader.rbI didn't change this at all, assuming that it needs a file path to store it at

def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

Then I pushed the new code and I got an application error. Can anyone help?

(Note,in the amazon console, when I create a bucket, it says "US Standard". I put the hyphen in my code because I saw that on the carrier wave git hub.)

part of the Heroku logs telling me there's been a crash

4T23:32:03+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize'
2012-01-14T23:32:03+00:00 app[web.1]:   from /app/config.ru:1:in `new'
2012-01-14T23:32:03+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.6/lib/rack/server.rb:301:in `wrapped_app'
2012-01-14T23:32:03+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:49:in `tap'
2012-01-14T23:32:03+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:49:in `<top (required)>'
2012-01-14T23:32:03+00:00 app[web.1]:   from script/rails:6:in `require'
2012-01-14T23:32:03+00:00 app[web.1]:   from script/rails:6:in `<main>'
2012-01-14T23:32:03+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.6/lib/rack/server.rb:252:in `start'
2012-01-14T23:32:03+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:40:in `eval'
2012-01-14T23:32:03+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:54:in `block in <top (required)>'
2012-01-14T23:32:05+00:00 heroku[web.1]: State changed from starting to crashed
2012-01-14T23:32:05+00:00 heroku[web.1]: Process exited
2012-01-14T23:32:06+00:00 heroku[router]: Error H10 (App crashed) -> GET mmcarry.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
2012-01-14T23:32:06+00:00 heroku[router]: Error H10 (App crashed) -> GET mmcarry.herokuapp.com/favicon.ico dyno= queue= wait= service= status=503 bytes=
2012-01-14T23:32:11+00:00 heroku[router]: Error H10 (App crashed) -> GET mmcarry.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
2012-01-14T23:32:11+00:00 heroku[router]: Error H10 (App crashed) -> GET mmcarry.herokuapp.com/favicon.ico dyno= queue= wait= service= status=503 bytes=
Was it helpful?

Solution

I think the issue you have is that the region name, while named "US Standard" is actually referred to as: "us-east-1" by fog. To fix this change this line:

:region => 'US-Standard'

to:

:region => 'us-east-1'

I think that should solve your problem.

OTHER TIPS

i think u should give config.fog_public = 'false', follow as below

CarrierWave.configure do|config|
 config.fog_credentials = {
  provider:              'AWS',
  aws_access_key_id:     'AWS_ACCESS_KEY',
  aws_secret_access_key: 'AWS_SECRET_KEY',
  region:                'region-name',
  host:                  's3.example.com',
  endpoint:              'https://s3.example.com'
 }
 config.fog_directory = 'name of the bucket'
 config.fog_public = 'false'
 config.fog_attributes = {'Cache-Control' => "max-age=#{365.to_i}" }
end

I think it's cause your :region is incorrect. The region is usually in this format: 'us-east-1', 'us-west-1', etc. Check which one you are in first and make the change and see?

Did you ever resolve this issue? I had a similar problem and it went away after changing the order of the gems in the Gemfile.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top