---
title: "Discussion on \"CKEditor5 Image Upload\" | Hashnode"
description: "Discussion on \"CKEditor5 Image Upload\". This blog post explains how to implement image upload in Rich Text Editor (CKEditor) within an Oracle APEX application."
url: "https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [CKEditor5 Image Upload](https://lmoreaux.hashnode.dev/ckeditor5-image-upload?utm_source=hashnode&utm_medium=feed)

This blog post explains how to implement image upload in Rich Text Editor (CKEditor) within an Oracle APEX application.

Jul 20, 2022 · 7 min read · lmoreaux.hashnode.dev  
Updated May 20, 2023  
Read the article

-   [#orclapex](https://hashnode.com/tag/orclapex)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#oracle](https://hashnode.com/tag/oracle)

## Written by

[Louis Moreaux](https://hashnode.com/@lmoreaux)

@lmoreaux · Paris

  
[View profile](https://hashnode.com/@lmoreaux)

Oracle APEX developer

Oracle APEX Developer (Insum) from Paris Contributor of Flows for APEX Passionate about APEX and web development.

## Responses 4

Markdown supported · ⌘↵ to post

[Javier Porrata](https://hashnode.com/@jporrata)

[May 19, 2023](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/6467270d7bd6d2e2dc873335)

Hi, When sending an email with the editor content images are not included or if included many emails clients does not allow or accept them. Do you know if there is a image hosting service we can integrate to hold the images uploaded to the ckeditor? So when sending an email the images are visible to the recipient.

Thanks for any help on this! Javier

[Louis Moreaux](https://hashnode.com/@lmoreaux)

[May 22, 2023](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/6467270d7bd6d2e2dc873335#reply-646bb5885ccc6321b7044176)

Hi Javier, This may be because the endpoints are protected. If you want the images to be visible in the body of the email, you probably need to unprotect the GET handler. I hope this helps. Louis

[Jonathan Rojas Monroy](https://hashnode.com/@jonathanrm98)

[Jan 30, 2023](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/63d7e768256a3e49144129bf)

Hello Louis, I love your posts about the CKEditor 5 with Oracle Apex... I am currently working on a migration fix from CKEditor 4 to CKEditor 5 because APEX 22.2 completely disables the use of CKEditor 4, the problem is that in CKEditor 4 it was possible to use an attribute configObject.filebrowserImageBrowseUrl in which it was possible to add your own APEX page to search images in the database, however, CKEditor 5 does not have this implementation. My idea is to modify the behavior of the uploadImage button (toolbar) through the methods without modifying the Drop Image (pasting images from clipboard)... do you have any idea how to simulate the configObject.filebrowserImageBrowseUrl functionality or how to modify only the behavior of the imageUpload button from clipboard? Sorry if I ask you these questions, literally reading your posts I could understand much better the use of the ckeditor 5 in oracle apex, thank you very much.

[Louis Moreaux](https://hashnode.com/@lmoreaux)

[Feb 7, 2023](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/63d7e768256a3e49144129bf#reply-63e29692cecce1c954ae0316)

Thank you for your comment, to be honest I haven't looked at that before so I have no ideas... But it seems to be an interesting topic. I might be interested in digging further

[Jonathan Rojas Monroy](https://hashnode.com/@jonathanrm98)

[Feb 7, 2023](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/63d7e768256a3e49144129bf#reply-63e2d4a43e27fed24914f5e2)

Thank you so much for replying! It's possible by killing the current behavior of a toolbar button and overriding it (using document selection) the action when clicking on it hahaha nice posts! I will keep reading them

[Nicolas Pilot](https://hashnode.com/@NPilot)

[Aug 5, 2022](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/62ecb0cacbce7c268014f9e0)

Hi Louis, Thank you for this amazing blog. It is very helpful.

### ORDS Security

Concerning the ORDS First Party Authentication (**Apex-Session**), do we need to setup something on ORDS for that to work ?

I've spent a lot of time trying to make it working but for some reason ORDS always return **401 Unauthorized** error. (I can see in the POST request of my browser the http header "apex-session" with the correct value but ORDS reject the request ).

I've tried using a ORDS OAUTH2 Token and it works properly.

### Image Store

Concerning the image storage, I'm not a big fan of storing blob inside the database.

And I also think that there is a better approach to send the images to the storage location without using ORDS and overloading the database with blob handling.

The idea is to send the image directly from the client browser to Google Cloud Storage (or another cloud storage).

GCS provide JSON API to "Initiate a resumable upload session" which return a secure upload URL. We only need to define a PL/SQL Function to initiate an upload session on GCS using OAUTH2 to return an "upload url" to the client. That way, the GCS oauth token is not visible by the client, which is something we want to avoid to secure the bucket content.

The challenge here is to be able to dynamically set the upload url of the "CKEditor Simple upload adaptor" by executing an AJAX Call to execute that PL/SQL function when the user pick an image... + Another challenge is the successful response that the "CKEditor Simple upload adapter" is waiting for : { "url":"....." } Maybe we would have to define a "Custom upload adapter"

Best Regards

-   Nicolas

[Louis Moreaux](https://hashnode.com/@lmoreaux)

[Aug 9, 2022](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/62ecb0cacbce7c268014f9e0#reply-62f20f28408d676b1b589150)

Hi Nicolas, Thank you for your comment, it means a lot.

To protect ORDS endpoint, you have to define a privilege and protect your module with this privilege. Have you follow this step? OAuth2 is also a valid approach.

I am also not a big fan of blob storage but it's really easy to make it working quickly. I am working on another post with images stored in an OCI bucket. Stay tuned :-)

[Nicolas Pilot](https://hashnode.com/@NPilot)

[Aug 9, 2022](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/62ecb0cacbce7c268014f9e0#reply-62f216b3408d676b1b5892ff)

[Louis Moreaux](https://hashnode.com/@lmoreaux) Thank you Louis, Yes, I've followed all the steps, and it is working fine for OAuth2, but for some reasons, the ORDS does not authorize my requests with the "Apex-Session" header. Maybe a cookie issue...

[oracle.com/application-development/technologies/r…](https://www.oracle.com/application-development/technologies/rest-data-services/listener-dev-guide.html)

Good news for your next post. Would be nice if the images could be sent directly from the client to OCI bucket without going through the database... this would save CPU & Bandwidth...

Another challenge is to be able to automatically compress and resize the images on the client side before uploading to OCI... ;-)

[Stefan Dobre](https://hashnode.com/@sdobre)

[Jul 20, 2022](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/62d833a4ca829b4aca5672d7)

Thanks Louis again for the blog post! Great job!

If I may add just 2 suggestions:

-   `apex.jQuery("#pFlowId").val()` can be written as `apex.env.APP_ID` and `apex.jQuery("#pInstance").val()` as `apex.env.APP_SESSION`
-   There is no need to pollute the "Execute when Page Loads" attribute. That bit can more elegantly be done directly in the item's JS Init Code:
    
    ```
    function(options){
      options.executeOnInitialization = editor => {
          editor.conversion.for...
      }
      return options;
    }
    ```
    

And a couple more things that you may still have to think about:

-   The content probably won't only be viewed from within the editor. Chances are you'll wish to just render the HTML in a static or dynamic content region somewhere. How would you go about appending that session token then?
-   You will most likely encounter the concept of "posts" as you won't only be editing the same content each time. In that case, how will you link a post to its images? That is, if a post is deleted, how will you also delete its images?
-   Similarly, say a user uploads an image, but never actually submits the page. What happens to these "unsaved" images?

I still don't have an elegant solution for these problems, but they're worth thinking about.

\- Stefan

[Jon Dixon](https://hashnode.com/@orclapex)

[Jul 20, 2022](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/62d833a4ca829b4aca5672d7#reply-62d8865fca829b4aca5680e0)

This is a great post, thank you!

One thing you try to improve security is to have the POST Handler in an ORDS module secured using OAuth2. Use `apex_web_service.oauth_authenticate` to get a token and then include the following in the CKEditor initialization to pass the bearer token:

```
      withCredentials: true,
      headers: {Authorization: 'Bearer &P10_OAUTH_TOKEN.'}
```

Having the POST handler secured by OAuth2 also allows other services to use it, not just APEX.

Keep the GET image handler in an unsecured ORDS Handler. Generate a random token when you add the image to the table. Append the token as a query string parameter to the URL returned in the POST response e.g.

```
{
    "url": "example.com/ords/get_ck_image/file/10
}
```

This way, images included in the HTML will show in a classic report, etc. `<img src="[example.com/ords/get_ck_image/file/13](https://www.example.com/ords/get_ck_image/file/13?file_token=BBF8RP5FCBU6EDYWtoUIIBJzZcotRK%22%3E)`

In the GET handler, include the token in the where clause:

```
select content_type, image
from ckeditor_images 
where id = :id
and image_token = :image_token
```

This isn't completely secure because someone could inspect the HTML and share the link. It does prevent people from trying to guess other image tokens though.

[Louis Moreaux](https://hashnode.com/@lmoreaux)

[Jul 21, 2022](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/62d833a4ca829b4aca5672d7#reply-62d8ecb8ca829b4aca568d25)

Thanks you [Stefan Dobre](https://hashnode.com/@sdobre) for taking the time to read and comment on it! First of all, I just updated the post with your two suggestions, by the way thanks for the executeOnInitialization, I hadn't seen that attribute.

To display images outside of CKEditor, I would opt for a replace function that will add the session token (I added a classic report on the blog example).

To add an uploaded image to a "post", we can use the CKEditor API to be able to create an image element from a stored image (example added as well).

If a post is deleted or the page is not submitted, I would let the user decide if he wants to delete the file or not. An interesting approach could be to create an APEX automation to check if a file is used in a post or not and delete it (based on the upload date, for example after 30 days).

I will update the post with these ideas soon.

[Louis Moreaux](https://hashnode.com/@lmoreaux)

[Jul 21, 2022](https://hashnode.com/posts/ckeditor5-image-upload/62d7d721ca829b4aca565e58/comment/62d833a4ca829b4aca5672d7#reply-62d8ee973df6e54ab8e5d928)

Hi [Jon Dixon](https://hashnode.com/@orclapex), Thanks for your comment, I also thought about using OAuth2 authentication and it is a valid approach but I wanted a really simple and APEX friendly solution. So I thought the session header was the right choice for this example. I think your comment is enough to document this second authentication mode.
