Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Upload Image in execute server-side code

Paulo A. KünzelOct 31 2023

Hello,

I had an app that would submit and process the form, but now the idea is to do it without reloading the whole thing (not submiting).

Create a dynamic action that would read the file and sabe it to a CLOB page item

const reader = new FileReader();
const file = document.querySelector("input[type=file]").files[0];

reader.addEventListener(
    "loadend",
    () => {
        apex.item("P1_TEMP_IMAGE_LOB").setValue(reader.result);
        apex.item("P1_IMAGE_MIME_TYPE").setValue(file.type);
    },
    false,
);

reader.readAsText(file);

and then, when the user pressed “send”, execute this PLSQL

declare
    l_image_blob blob;
begin

    l_image_blob := apex_util.clob_to_blob(:P1_TEMP_IMAGE_LOB);

    insert into CHAT_MESSAGES(TEXT, ID_CHAT_CODE_TYPE, CODE, IMAGE_MIME_TYPE, IMAGE)
    values (:P1_TEXT_MESSAGE, :P1_CODE_TYPE, :P1_CODE, :P1_IMAGE_MIME_TYPE, l_image_blob);
end;

It all runs apprently well, but the images don't load as if “corrupted” or broken.

I did some tests, and when selecting the same image uploaded through the old process, the blob seems to be different from the one in the new process, so I'm probably not supposed to do that or the encoding is wrong or something.

Any tips, link or help?

This post has been answered by Ed Jones-Oracle on Nov 1 2023
Jump to Answer
Comments
Post Details
Added on Oct 31 2023
6 comments
406 views