I'm using paperclip to store pictures on Amazon S3. It works fine if I upload via a normal form, but I also want to set users' profile pictures to their facebook picture by default if they are registering with facebook via omniauth.
It sets the picture file size, the name and all the other fields properly. It even sets the correct link when I call
<%= image_tag @user.profile_picture.url(:small) %>
But for some reason the image does not get stored.
Again, if I upload with a form it uploads the picture fine.
<%= f.label :profile_picture %>
<%= f.file_field :profile_picture %>
How I try to parse the image from the link on registration:
user.profile_picture=URI.parse(auth.info.image)
My paperclip configuration:
has_attached_file :profile_picture, styles: { small: "150x150>" },
path: "app/public/uploads/profile_pictures/:id/:style/:basename.:extension",
validates_attachment_content_type :profile_picture, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
validates_attachment_size :profile_picture, less_than: 2.megabytes
My production.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']
}
}
Paperclip.rb initializer:
Paperclip::Attachment.default_options[:s3_host_name] = 's3-eu-west-1.amazonaws.com'