title: Inserting an image into a table in Oracle Apex
body: <p>I have created a form based on the following table: </p>
  
  <pre><code>CREATE TABLE  "POSTS" 
     (    "POST_ID" NUMBER(15,0) NOT NULL ENABLE, 
      "USER_ID" VARCHAR2(30) NOT NULL ENABLE, 
      "TITLE" VARCHAR2(255) NOT NULL ENABLE, 
      "TEXT" CLOB, 
      "RESPONSE_TO" NUMBER(15,0), 
      "FLAGGED" CHAR(1), 
      "MIMETYPE" VARCHAR2(50), 
      "LAST_UPDATE" DATE, 
      "THUMB" BLOB, 
      "IMAGE" "ORDSYS"."ORDIMAGE" , 
      "FILENAME" VARCHAR2(255), 
       CONSTRAINT "POSTS_PK" PRIMARY KEY ("POST_ID")
    USING INDEX  ENABLE
     )
  /
  ALTER TABLE  "POSTS" ADD CONSTRAINT "POSTS_CON" FOREIGN KEY ("RESPONSE_TO")
        REFERENCES  "POSTS" ("POST_ID") ENABLE
  /
  
  
  CREATE INDEX  "POSTS_TEXT_INDEX" ON  "POSTS" ("TEXT") 
     INDEXTYPE IS "CTXSYS"."CONTEXT"
  /
  
  
  CREATE INDEX  "POSTS_TITLE_INDEX" ON  "POSTS" ("TITLE") 
     INDEXTYPE IS "CTXSYS"."CONTEXT"
  /
  
  
  CREATE OR REPLACE EDITIONABLE TRIGGER  "BI_POSTS" 
    before insert on "POSTS"               
    for each row  
  begin   
    if :NEW."POST_ID" is null then 
      select "POSTS_SEQ".nextval into :NEW."POST_ID" from sys.dual; 
    end if; 
  end; 
  
  /
  ALTER TRIGGER  "BI_POSTS" ENABLE
  /
  
  
  CREATE OR REPLACE EDITIONABLE TRIGGER  "NEW_POST" 
    BEFORE INSERT
    ON posts
  
  FOR EACH ROW
  BEGIN
    --l_image := ORDSYS.ORDImage.Init();
    --ORDSYS.ORDImage.process(:new.image, 'maxscale=200 200');
  
    :new.user_id := v(':APP_USER');
    --process_post_image(:new.post_id);
  END;
  
  /
  ALTER TRIGGER  "NEW_POST" ENABLE
  /
  </code></pre>
  
  <p>The title, text and filename fields are editable in the form.</p>
  
  <p>To upload the file the following code is used in a custom process in place of the automatically generated insert code:</p>
  
  <pre><code>DECLARE
  
    l_upload_size INTEGER;
    l_upload_blob BLOB;
    l_image_id    NUMBER;
    l_image       ORDSYS.ORDImage;
  
  BEGIN
  
    --
    -- Get the BLOB of the new image from the APEX_APPLICATION_TEMP_FILES (synonym for WWV_FLOW_TEMP_FILES)
    -- APEX 5.0 change from APEX_APPLICATION_FILES which has been deprecated
    -- APEX_APPLICATION_TEMP_FILES has fewer columns and is missing doc_size
    --
  
    SELECT
      blob_content
    INTO
      l_upload_blob
    FROM
      apex_application_temp_files
    WHERE
      name = :P16_FILENAME;
    --
    -- Insert a new row into the table, initialising the image and
    -- returning the newly allocated image_id for later use
    --
    INSERT
    INTO
      posts
      (
        post_id,
        title,
        text,
        filename,
        image
      )
      VALUES
      (
        posts_seq.nextval,
        :P16_TITLE,
        :P16_TEXT,
        :P16_FILENAME,
        ORDSYS.ORDImage()
      )
    RETURNING
      post_id, image
    INTO
      l_image_id, l_image;
  
    -- find the size of BLOB (get doc_size)
    l_upload_size := dbms_lob.getlength(l_upload_blob);
    -- copy the blob into the ORDImage BLOB container
    DBMS_LOB.COPY( l_image.SOURCE.localData, l_upload_blob, l_upload_size );
  
    -- set the image properties
    l_image.setProperties(); 
  
    UPDATE
      posts
    SET
      image     = l_image -- original ORDImage image
    WHERE
      post_id = l_image_id;
  
  END;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/AhzzE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AhzzE.png" alt="location of the custom process"></a></p>
  
  <p>But the following error is produced:</p>
  
  <pre><code>Invalid action CREATE on this object. (D)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/qO4HT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qO4HT.png" alt="enter image description here"></a></p>