Rachel9494
Rachel9494

Reputation: 824

Ruby on Rails with Figaro and Paperclip

I'm using localhost right now and installed the Figaro gem to help me test using Paperclip with my S3 bucket. When I try to upload something, I get this message:

missing required :bucket option

In development.rb I inserted the following code:

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']
  }
}

And then I placed the following code in the Figaro-generated application.yml file:

development:
  AWS_BUCKET: (the actual name of my bucket)
  AWS_ACCESS_KEY_ID: (the actual access key)
  AWS_SECRET_ACCESS_KEY: (etc)

I will say that when I declare what the bucket is directly into the model I'm using for this, it does seem to work (a new folder is generated in my bucket) but the image never actually appears in the destination (perhaps a separate issue or perhaps not).

I know I am missing something obvious here, I'm probably not doing something right. Using Rails v4 with aws-sdk v1.34 and Figaro v0.7.0. Thanks to anyone who can help me.

Upvotes: 0

Views: 999

Answers (2)

Richard Peck
Richard Peck

Reputation: 76774

Further to your comment, this is live code which is 100% working for us right now:

config.paperclip_defaults = {
    storage: :s3,
    s3_host_name: 's3-eu-west-1.amazonaws.com',
    s3_credentials: {
      access_key_id: ENV['AWS_ACCESS_KEY_ID'],
      secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
    },
    bucket: ENV['S3_BUCKET_NAME']
}

Also make sure you restart your rails server each time you change these details. Reason being the config files are loaded at initialization, and maintained for the server's session

Upvotes: 1

steakchaser
steakchaser

Reputation: 5249

I think there is just a syntax typo. ENV is a variable; it's a hash and not a symbol. Just remove the : from in front of ENV. It should be:

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']
  }
}

Upvotes: 1

Related Questions