In this Oracle APEX Tutorial, I will explain to you How to Upload File to Directory in Oracle APEX.
So I have followed some steps for the oracle apex upload file into the directory.
How to Upload File to the Directory in Oracle APEX?
Step 1:- Create a Folder into your local system I have created an image folder into my E:\images. The below screenshot will help you.
Step 2: Now Open CMD and connect with sys user and run bellow script:
create directory upload_image_dir as 'E:\upload_images';grant read on directory upload_image_dir to anonymous;grant read on directory upload_image_dir to admin;
Step 3: Create a page item with the file browse option which will use for uploading images.
Step 4:Create Page process for uploading the file into a directory as per the below screenshot and code:
DECLAREV_IMAGE APEX_APPLICATION_TEMP_FILES.BLOB_CONTENT%TYPE;V_FILENAME APEX_APPLICATION_TEMP_FILES.FILENAME%TYPE;BEGINBEGINSELECT BLOB_CONTENT,FILENAME INTO V_IMAGE,V_FILENAMEFROM APEX_APPLICATION_TEMP_FILESWHERE UPPER(NAME)=UPPER(:P7_IMAGE);EXCEPTION WHEN NO_DATA_FOUND THENV_IMAGE:=NULL;V_FILENAME:=NULL;WHEN OTHERS THENV_IMAGE:=NULL;V_FILENAME:=NULL;END;IF V_IMAGE IS NOT NULL AND V_FILENAME IS NOT NULL THENSAVEFILE(V_IMAGE,'UPLOAD_IMAGE_DIR',V_FILENAME);ELSEAPEX_ERROR.ADD_ERROR (p_message => 'Image Not Upload',p_display_location => apex_error.c_inline_in_notification );END IF;END;
Note: Directory name should be in an upper case like "UPLOAD_IMAGE_DIR".
Step 5: Now finally create the database procedure for uploading a file into a local directory.
create or replace PROCEDURE SaveFile(FileContent IN OUT NOCOPY BLOB, FolderName IN VARCHAR2, FileName IN VARCHAR2)ISBUFFER RAW(1024);OFFSET PLS_INTEGER := 1;FileLength PLS_INTEGER;amount PLS_INTEGER := 1024;fhandle UTL_FILE.FILE_TYPE;BEGINFileLength := DBMS_LOB.GETLENGTH(FileContent);fhandle := UTL_FILE.FOPEN(FolderName, FileName, 'wb');LOOPEXIT 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);EXCEPTIONWHEN OTHERS THENIF UTL_FILE.IS_OPEN(fhandle) THENUTL_FILE.FCLOSE(fhandle);END IF;RAISE;END SaveFile;
If You Like This Tutorial Please Like Share And Comment.
1 Comments
Can We Save Multiple Files at a time?
ReplyDeleteIf you have any doubts, Please let me know