Ckeditor with Amazon S3 and paperclip.

I was working on project recently, where I had to use CKeditor with paperclip and amazon s3 as the storage. This all is running on Heroku. The solution is really easy. You have the paperclip in you model

has_attached_file :avatar,
 :styles => { :big => "180x180#", :medium => "140x140#" },
 :storage => :s3,
 :s3_credentials => "#{Rails.root}/config/s3.yml",
 :path => ":attachment/:id/:style.:extension",
 :url => ":s3_domain_url"
And you have something like this in the picture.rb and attachment_file.rb (app/model/ckeditor/)
has_attached_file :data,
     :url => "/ckeditor_assets/attachments/:id/:filename",
     :path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"

So solution is obvious now:

has_attached_file :data, :styles => { :big => "180x180#", :medium => "140x140#"},
 :storage => :s3,
 :s3_credentials => "#{Rails.root}/config/s3.yml",
 :path => ":attachment/:id/:style.:extension",
 :url => ":s3_domain_url"

That’s it.

4 Replies to “Ckeditor with Amazon S3 and paperclip.”

  1. I’m kinda confused here. I’m using ckeditor to edit the content body of a post, which can obviously have many or no images at all.

    It works without me having to add has_attached_file in my Post.rb model, but i can’t configure it with S3. It uses the local filesystem.

    This is my model:

  2. Ok so I upload image via CKeditor UI. Then paperclip get data from CKeditor and process them and save them to S3 or to localholost. So if you would like to upload images from CKeditor to S3 you need another gem (like paperclip) to do the upload part. Maybe there is another way how to configure CKeditor but I don’t know about it.
    I hope that my response make sense to you :)

Leave a Reply

Your email address will not be published. Required fields are marked *