CKEditor5 Image Upload - Additional thoughts
Introduction
After publishing an article on CKEditor5 Image Upload, I received a comment from Stefan Dobre from the Oracle APEX team that made me think about how to handle image uploads in a more clever way:
And a couple more things that you may sti...
lmoreaux.hashnode.dev5 min read
Thank you Louis, your article inspires me a lot.
Because I tried to implement the image upload before this wrap-up, I took some different implementation. Let me share.
Firstly the content of CKEditor stores in APEX Collection then copied to the table after Automatic-DML process by the code below.
Text is stored in CKE_DOCUMENTS.CONTENT and CKE_IMAGES.DOCUMENT_ID is referring CKE_DOCUMENTS.ID.
declare l_clob clob; l_link varchar2(32767); l_id varchar2(80); i pls_integer; l_images apex_t_varchar2; begin select clob001 into l_clob from apex_collections where collection_name = :P2_COLLECTION and seq_id = 1; update cke_documents set content = l_clob where id = :P2_ID; -- find all image url from the content. i := 1; while true loop -- retrieve the image url with the id l_link := regexp_substr(l_clob, :G_IMAGE_URL || '/([0-9]+)',1,i); if l_link is null then exit; else i := i + 1; -- get image id from the url and remember it. l_id := regexp_replace(l_link, :G_IMAGE_URL || '/([0-9]+)', '\1'); apex_string.push(l_images,l_id); end if; end loop; -- initialize the images linked to the document, no effect on new doc. update cke_images set document_id = null where document_id = :P2_ID; -- link image to the document. update cke_images set document_id = :P2_ID where id in (select column_value from table(l_images)); end;Since cascade delete is enabled, any images linked to the document will be deleted along with the document. Images may remain, but housekeeping is simple (just delete the image without document_id).