I try for two days to make my all web site work on the internet through Heroku and Amazon AWS S3 ( to store my images ) but ... I can\'t make it !
To make it simpli
Try this url. this will give you a help.
http://www.peoplecancode.com/en/tutorials/uploading-images-on-heroku-saving-to-aws-s3-using-fog
Can you post your Photo
class?
From the logs
Paperclip::Error (Photo model missing required attr_accessor for 'image_file_name'):
It looks to me like you don't have the has_attached_file
defined on your class.
From the tutorial you linked:
class Friend < ActiveRecord::Base
# You will need to use attr_accessible if you are
# using Rails config setting `whitelist_attributes = true`
attr_accessible :avatar
# This method associates the attribute ":avatar" with a file attachment
has_attached_file :avatar, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
end
If you do have this (or something similar) then you probably need to make a migration to get that column in your database:
add_attachment :photos, :image
Which will add the correct columns to your photos
table.
With the has_attached_file
and the columns on your table, I don't think you should have any (or at least the same) problems
Had this problem before!
Solved it by putting the bucket vars in the model itself (live code):
#app/models/image.rb
has_attached_file :image,
:styles => { :medium => "x300", :thumb => "x100" },
:default_url => "**********",
:storage => :s3,
:bucket => '*****',
:s3_credentials => S3_CREDENTIALS
#config/application.rb
config.paperclip_defaults = {
:storage => :s3,
:s3_host_name => 's3-eu-west-1.amazonaws.com'
}
#config/initializers/s3.rb
if Rails.env == "production"
# set credentials from ENV hash
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "*****"}
else
# get credentials from YML file
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
#config/application.yml ([figaro][1] gem)
S3_KEY: ********
S3_SECRET: **********
We also have this in our production.rb:
#app/environments/production.rb
config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
The ENV['FOG_DIRECTORY']
is the bucket name, and there's also one for different regions. Here's a very good resource for you (the answer with 15 upvotes... not the accepted answer)