I used carrier wave and fog to load on Amazon S3. Here's what it looks like, I'll skip some of the fog, and you may need to make some adjustments. However, the concept is simple.
I used angularJS, but jquery parameters should look like this. You will need to determine the download route using the POST method.
javascript:
<script> $(function() { $('.selector').froalaEditor({ // Set the image upload URL. imageUploadURL: '/attachment/upload.json', imageUploadMethod: 'POST' }) } </script>
Then you will need to implement /attachment/upload.json.
In Rails
-- attachment.rb class Attachment < ActiveRecord::Base mount_uploader :picture, PictureUploader end
Since this is an ajax call, you will need to process the CSRF token in your controller when sending. This example will skip verification: so add skip_before_filter: verify_authenticity_token in your controller. If you do not want to skip the check. you need to pass the parameter in Froala initialization using imageUploadParams: {'authenticity_token': your csrf token}. Therefore release part of the rails.
-- attachments_controller.rb class AttachmentsController < ApplicationController skip_before_filter :verify_authenticity_token ... def upload # The Model: Attachment, created below. @attachment = Attachment.new @attachment.picture = params[:file] @attachment.save respond_to do |format| format.json { render :json => { status: 'OK', link: @attachment.picture.url}} end end ... end
Using rails generates a PictureUploader and creates a model in the console
rails generate uploader Picture rails g model attachment picture:string rake db:migrate
In your route.rb, configure the route using the # controller method
post 'attachment/upload' => 'attachments#upload'
This way you will have a route / attachment / upload via POST, and it causes the application to load #. Hope it helps! Let me know if anything bothers you.
Nate cheng
source share