Image Server Upload





How it works

  1. Specify upload options when initializing the editor.
  2. On image insertion, the editor automatically makes an AJAX request to the server.
  3. Once the request reaches the server, it stores the image and sends back to the client the link to the uploaded image.

Initialize the editor

First, add the imageUploadURL option, as its value enter the upload destination for the images. 

Next, set any additional options to configure upload methods and allowed file types: imageUploadParamimageUploadParamsimageUploadMethodimageMaxSizeimageAllowedTypes.


<script>
new FroalaEditor('.selector', {
// Set the image upload URL.
imageUploadURL: '/upload_image'
})
</script>



Receive the uploaded image and store it


Return the path to the uploaded image





<script>
  new FroalaEditor('.selector', {
    // Set the image upload URL.
    imageUploadURL: '/upload_image'
  })
  </script>


# Django
from django.http import HttpResponse
import json
from froala_editor import Image
from froala_editor import DjangoAdapter

def upload_image(request):
  try:
    response = Image.upload(DjangoAdapter(request), '/public/')
  except Exception:
    response = {'error': str(sys.exc_info()[1])}
  return HttpResponse(json.dumps(response), content_type="application/json")