Days
Hours
Minutes
Seconds
x

Froala Editor v4.2.0 is Here LEARN MORE

Skip to content

Ruby File Server Upload

How it works

  1. You specify the upload options when the rich text editor is initialized on client side.
  2. When an file is inserted, the javascript editor automatically makes an AJAX request to the server.
  3. Once the request hits the server, it stores the file and sends back to the client the link to the uploaded file.

Jump to Complete Example

Initialize the javascript editor

To get started, the rich text editor needs to have the fileUploadURL option set as the URL where you want to have the files uploaded. Additionally, you can set other options related to the way the files are being uploaded and what data your server receives: fileUploadParam, fileUploadParams, fileUploadMethod, fileMaxSize, fileAllowedTypes.

<script>
  $(function() {
    $('.selector').froalaEditor({
      // Set the file upload URL.
      fileUploadURL: '/upload_file'
    })
  });
</script>

Receive the uploaded file and store it

The server implementation is responsible for receiving the request and handling it appropriately. In Ruby, the uploaded file is available in the params global variable. The Ruby editor SDK is designed to automatically detect the uploaded file, so you just have to specify the path where to store it.

Note: The path of the file is relative to the Rails.root global variable.

FroalaEditorSDK::File.upload(params)

For the uploaded file to be stored correctly, the server should have the rights to write in the uploads folder. Additionally, you should check that the uploaded file is public accessible in browser so it can be displayed to your users.

Return the path to the uploaded file

If the save action is completed successfully, the SDK is generating an FileResponse object with the absolute path to the uploaded file, so your server just have to return it back to the client side.

render :json => FroalaEditorSDK::File.upload(params)

Complete Example

<script>
  $(function() {
    $('.selector').froalaEditor({
      // Set the file upload URL.
      fileUploadURL: '/upload_file'
    })
  });
</script>
class UploadController < ActionController::Base

  ...

  def upload_file
    render :json => FroalaEditorSDK::File.upload(params)
  end

  ...

end
[class^="wpforms-"]
[class^="wpforms-"]
[bws_google_captcha]
<div class="gglcptch gglcptch_v2"><div id="gglcptch_recaptcha_1701998904" class="gglcptch_recaptcha"></div> <noscript> <div style="width: 302px;"> <div style="width: 302px; height: 422px; position: relative;"> <div style="width: 302px; height: 422px; position: absolute;"> <iframe src="https://www.google.com/recaptcha/api/fallback?k=6Ld6lNoUAAAAAM626LfCOrnkBFJtYZAKESFCjgv_" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe> </div> </div> <div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;"> <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px !important; height: 40px !important; border: 1px solid #c1c1c1 !important; margin: 10px 25px !important; padding: 0px !important; resize: none !important;"></textarea> </div> </div> </noscript></div>
[class^="wpforms-"]
[class^="wpforms-"]
[bws_google_captcha]
<div class="gglcptch gglcptch_v2"><div id="gglcptch_recaptcha_2048240583" class="gglcptch_recaptcha"></div> <noscript> <div style="width: 302px;"> <div style="width: 302px; height: 422px; position: relative;"> <div style="width: 302px; height: 422px; position: absolute;"> <iframe src="https://www.google.com/recaptcha/api/fallback?k=6Ld6lNoUAAAAAM626LfCOrnkBFJtYZAKESFCjgv_" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe> </div> </div> <div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;"> <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px !important; height: 40px !important; border: 1px solid #c1c1c1 !important; margin: 10px 25px !important; padding: 0px !important; resize: none !important;"></textarea> </div> </div> </noscript></div>
[class^="wpforms-"]
[class^="wpforms-"]
[bws_google_captcha]
<div class="gglcptch gglcptch_v2"><div id="gglcptch_recaptcha_1283336579" class="gglcptch_recaptcha"></div> <noscript> <div style="width: 302px;"> <div style="width: 302px; height: 422px; position: relative;"> <div style="width: 302px; height: 422px; position: absolute;"> <iframe src="https://www.google.com/recaptcha/api/fallback?k=6Ld6lNoUAAAAAM626LfCOrnkBFJtYZAKESFCjgv_" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe> </div> </div> <div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;"> <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px !important; height: 40px !important; border: 1px solid #c1c1c1 !important; margin: 10px 25px !important; padding: 0px !important; resize: none !important;"></textarea> </div> </div> </noscript></div>