INTRODUCTION:

The well-liked web development framework Oracle Application Express (APEX), you may create database-driven web apps fast and effectively. One of the features of APEX is the ability to upload and display images. This topic will demonstrate how to save photos in APEX to both a local directory and a server directory.

WHY WE NEED TO DO / CAUSES:

A web application feature like Oracle APEX’s ability to save photos into a local directory might be useful for a number of reasons. Here are some reasons why adding this feature would be a good idea.

  • Offline Access
  • Faster Load Times
  • Offline Editing and Annotations
  • Custom Image Manipulation

Implementing image saving to a local directory should be done thoughtfully and with proper planning to ensure a seamless user experience and data management.

HOW DO WE SOLVE:

STEP 1: In Oracle Apex, create a new process application, name it “Save Image in Local & Server Directory” and create a blank page & name it J&J Saved Image

STEP 2: Click the Shared Components -> Other Components -> Plug-in -> click the Import Button -> SQL Name ‘dyanamic_action_plugin_cam_ints – > Then, Filename is saved under ‘CAM-Integration’.

Inside SQL Query of ‘Dynamic_action_plugin_cam_ints’ plug-in:

DECLARE
l_collection_name VARCHAR2(100);
l_clob CLOB;
l_blob BLOB;
l_filename VARCHAR2(100);
l_mime_type VARCHAR2(100);
l_token VARCHAR2(32000);

BEGIN
— get defaults
l_filename := ‘snap_’ ||
to_char(SYSDATE,
‘YYYYMMDDHH24MISS’) || ‘.png’;
l_mime_type := ‘image/png’;
— build CLOB from f01 30k Array
dbms_lob.createtemporary(l_clob,
FALSE,
dbms_lob.session);

FOR i IN 1 .. apex_application.g_f01.count LOOP
l_token := wwv_flow.g_f01(i);

IF length(l_token) > 0 THEN
dbms_lob.writeappend(l_clob,
length(l_token),
l_token);
END IF;
END LOOP;
l_blob := apex_web_service.clobbase642blob(p_clob => l_clob);
l_collection_name := ‘PHOTOS’;
— check if exist
IF NOT
apex_collection.collection_exists(p_collection_name => l_collection_name) THEN
apex_collection.create_collection(l_collection_name);
END IF;
IF dbms_lob.getlength(lob_loc => l_blob) IS NOT NULL THEN
apex_collection.add_member(p_collection_name => l_collection_name,
p_c001 => l_filename, — filename
p_c002 => l_mime_type, — mime_type
p_d001 => SYSDATE, — date created
p_blob001 => l_blob); — BLOB img content
END IF;
exception when others then
raise_application_error(-20001,DBMS_UTILITY.format_error_backtrace);
END;

STEP 3: Then, Copy & Compile below the code (Procedure) and name it as SaveImageFile.

create or replace PROCEDURE SaveImageFile(

FileContent IN   BLOB

, FolderName IN VARCHAR2

, FileName IN VARCHAR2)

IS

BUFFER RAW(1024);

OFFSET PLS_INTEGER := 1;

FileLength PLS_INTEGER;

amount PLS_INTEGER := 1024;

fhandle UTL_FILE.FILE_TYPE;

BEGIN

FileLength := DBMS_LOB.GETLENGTH(FileContent);

fhandle := UTL_FILE.FOPEN(FolderName, FileName, ‘wb’);

LOOP

EXIT WHEN OFFSET > FileLength;

DBMS_LOB.READ(FileContent, amount, OFFSET, BUFFER);

UTL_FILE.PUT_RAW(fhandle, BUFFER, TRUE);

OFFSET := OFFSET + amount;

END LOOP;

UTL_FILE.FCLOSE (fhandle);

EXCEPTION

WHEN OTHERS THEN

IF UTL_FILE.IS_OPEN(fhandle) THEN

UTL_FILE.FCLOSE(fhandle);

END IF;

RAISE;

END SaveImageFile;

STEP 4: Create a region -> Button -> Dynamic Action on this page “J&J Saved Image” and in Dynamic Action -> Identification -> Action -> Cam_Integration. Affected Elements -> select type -> Region -> Image Data and Save it.

STEP 5: Create an Another Region & name it as Display Image -> Interactive Report -> set the type as SQL Query.

CODE:

Select dbms_lob.getlength(blob001) image , c001 file_name,

c002 MIME_TYPE,

seq_id,

d001 TIMESTAMP from apex_collections where collection_name =’PHOTOS’

STEP 6: Select the Display Image Region -> Columns -> Image -> Blob Attributes -> BLOB Column -> BLOB001 -> Primary Key -> SEQ_ID and Save it.

STEP 7:  Create a process & name it as Minimize the Image and set the type as PLSQL query and set the server-side condition -> when button pressed -> SAVE button.

CODE:

DECLARE

V_BLOB BLOB;

C_name varchar2(100);

BEGIN

SELECT blob001,c001  INTO V_BLOB,C_name

from apex_collections where collection_name =’PHOTOS’;

SAVEIMAGEFILE (V_BLOB,’SAVE_IMAGES’,C_name);

END;

STEP 8: Create a Directory path using SQL PLUS app and copy & compile the SQL Query and select the folder to be save and generate it.

CODE:

CREATE DIRECTORY SAVE_IMAGES2 AS ‘D:\SAVE_IMAGES’;

GRANT ALL ON DIRECTORY ING_IMAGE TO MAKESS;

STEP 9: Before Create a button and name it as Clear & Create a process & name it as Clear the Image and set the type as PLSQL query and set the server-side condition -> when button pressed -> Clear button and save & run it.

CODE:

APEX_COLLECTION.TRUNCATE_COLLECTION (p_collection_name => ‘PHOTOS’);

STEP 10: Then Run this Application to perform its function and Click the open icon to capture the required image & save it. The saved image will be displayed in the Interactive report and again click the save button to store that image in the local directory “D:\SAVE_IMAGES” and it’s completed.

CONCLUSION:

This functionality enables both users and developers to use photos in a more flexible and effective way. Local image storage does have many benefits. In the end, the choice to save photos to a local directory should be in accordance with the particular requirements and objectives of the program and its user base.

Recent Posts

Start typing and press Enter to search