Steve Benjamins
Steve Benjamins

Reputation: 21

S3 / Paperclip working on Heroku but not Localhost

Paperclip works perfectly for my app on Heroku, but I can't seem to get it working locally. Every time I try to do something I get an "missing required :bucket option" ... but the bucket is there and it works on Heroku!

Here's my model if it helps:

  has_attached_file :screen_one, :styles => { :medium => "800x600>", :thumb => "110x80#" },
  :storage => :s3,
  :s3_credentials => {
    :access_key_id => ENV['accesskeyishere'],
    :bucket => ENV['sitebuilderreport'],
    :secret_access_key => ENV['secretaccesskeyishere']
  }

I've changed the access keys since this is a public post :)

Upvotes: 2

Views: 2627

Answers (5)

Ben
Ben

Reputation: 1342

I had the same problem and I had config/application.yml (not sure if its a legacy thing or where it came from) but this allows environment variables to be set within rails 'codebase'. I forgot it was here, ignored in heroku and was overriding some settings that were not set.doh!

Upvotes: 0

user578828
user578828

Reputation: 101

You should define the ENV[] variables in your user .bash_profile in mac os.

You should do "heroku config" to see your heroku environement keys for S3 and define it in your local environement.

For example:

$ heroku config

AWS_ACCESS_KEY_ID: your_S3_XXX_key<br />
AWS_SECRET_ACCESS_KEY: your_secret_XXX_key<br />
AWS_BUCKET: your_production_bucket<br />
DATABASE_URL: postgres://xxxxxxx<br />
[...]<br />

You should copy the access_key and secret in your .bash_profile file:

export AWS_ACCESS_KEY_ID=your_S3_XXX_key<br />
export AWS_SECRET_ACCESS_KEY=your_secret_XXX_key
export AWS_BUCKET=your_development_bucket => "Specify new bucket for your dev environement".

Upvotes: 2

cbartondock
cbartondock

Reputation: 683

In case anyone is doing the same silly thing I did - and making a local script to source that exports all of the AWS environment variables - be sure you source it in the same Terminal session that you're generating the rails server in! If you use split windows (CMD SHIFT D), bear in mind that sourcing the proper environment variables in one does not do so in the other. Very silly mistake but I'm sure (or at least mildly hopeful) that I won't be the only one who makes it.

Upvotes: 1

bswinnerton
bswinnerton

Reputation: 4721

You can also simply use (filling in the correct values of course):

config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
      :bucket => 'AWS_BUCKET',
      :access_key_id => 'AWS_ACCESS_KEY_ID',
      :secret_access_key => 'AWS_SECRET_ACCESS_KEY'
    }
}

Upvotes: 0

Tu H.
Tu H.

Reputation: 496

I met the same problem (missing :bucket every single where). The answer below works perfectly in my case.

a. Add these to .bash_profile (Note: Fill in with your Amazon account credentials)

export AWS_ACCESS_KEY_ID=XXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXX
export AWS_BUCKET=XXXXXXXXXX

b. This is my development.rb (Note: Copy and paste without changing anything)

Paperclip.options[:command_path] = "/usr/local/bin/"

config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
      :bucket => ENV['AWS_BUCKET'],
      :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
      :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
    }
}

Be sure you rebundle your Rails app with the latest paperclip and aws-s3 gems. Also, make sure you quit your Terminal and run everything again since this is an update to your .bash_profile file.

I hope everything works out now.

Upvotes: 6

Related Questions