I've been trying to make Paperclip (gem version 4.2) work with amazon s3 (gem version 1.66) in a simple blog for two days and would appreciate any advice you all can provide.
Everything works fine on Heroku--the images upload to my bucket and display correctly--but locally I'm getting the error "missing required :bucket option" when I try to attach an image to an article.
What am I missing here?
I've tried the solutions in this and this and this and this related SO post with no luck.
Thanks.
production.rb and development.rb
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
env.rb
ENV['s3_bucket'] = 'edited_mybucketname'
ENV['aws_access_key_id'] = 'edited_myaccesskey_id'
ENV['aws_secret_access_key'] = 'edited_mysecretkey'
ENV['AWS_REGION'] = 'us-east-1'
aws.rb
AWS.ACCESS_KEY_ID = ENV["AWS_ACCESS_KEY_ID"]
AWS.SECRET_ACCESS_KEY = ENV["AWS_SECRET_ACCESS_KEY"]
AWS.REGION = ENV['AWS_REGION']
S3.BUCKET_NAME = ENV["S3_BUCKET_NAME"]
_form.html.erb
<%= form_for @article, html: {multipart: true} do |f| %>
<% if @article.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@article.errors.count, "error") %> prohibited
this article from being saved:
</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<p>
<%= f.label :image %><br>
<%= f.file_field :image %>
</p>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
show.html.erb
<%= image_tag @article.image.url(:large), :class => "img-responsive" %>
Gemfile
source 'https://rubygems.org'
ruby '2.3.0'
gem 'rails', '4.2.2'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'bootstrap-sass', '~> 3.3', '>= 3.3.6'
gem "font-awesome-rails"
gem 'paperclip', '~> 4.2'
gem 'aws-sdk', '~> 1.66'
gem 'simple_form'
gem 'mail_form'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
end
group :production do
gem 'rails_12factor', '~> 0.0.3'
end
Case matters with ENV Vars: ENV['s3_bucket']
(from your env.rb files) is not the same as the ENV['S3_BUCKET']
call elsewhere.
On Heroku, you can run heroku config -a your_app_name | grep bucket
to confirm that it is indeed uppercased on Heroku. (Assuming you're on a *nix machine).