Oracle APEX Page for File Upload & Download From Directory Instead of Table


File Upload & Download from Directory Instead of Table 



1)

create table testt1 
(
DOCNO number
       FILE_NAME varchar2(250),
       FILE_MIMETYPE varchar2(250),
       FILE_CHARSET varchar2(250)
)

2)  Conn as sys User 

  Sql> create or replace  directory TEST as 'C:\Test';
  Sql>  Grant read,write on directory to <user>

3)

   create or replace view v_testt1 as (
       select 
       DOCNO,
       FILE_NAME,
       FILE_MIMETYPE,
       FILE_CHARSET,
         TO_BLOB((select BFILENAME('TEST', File_Name ) from dual  )) DOCIMG ,
       sys.dbms_lob.getlength( BFILENAME('TEST', case when FILE_MIMETYPE is not null then 
       File_Name end)) Download from testt1
       where FILE_MIMETYPE is not null
   )

4) Login to Oracle APEX and create the Blank Page with Two region 

       --> File Upload (Static Region)

                    1) Create P10_File Item --> item Type - File Browser
                    2) Create Upload Button  (this will call the upload process )

       --> Document (Interactive Report Region)



Change Download Column Type as  Download BLOB



go to BLOB Attributes property and do necessary changes 




Go to Processing --> Create Upload Process and define the Upload Code 



DECLARE
V_IMAGE APEX_APPLICATION_TEMP_FILES.BLOB_CONTENT%TYPE;
V_FILENAME APEX_APPLICATION_TEMP_FILES.FILENAME%TYPE;
v_mime_type APEX_APPLICATION_TEMP_FILES.mime_type%TYPE;
BEGIN
BEGIN
SELECT BLOB_CONTENT,FILENAME,mime_type INTO V_IMAGE,V_FILENAME,v_mime_type
FROM APEX_APPLICATION_TEMP_FILES
WHERE UPPER(NAME)=UPPER(:P10_FILE);
EXCEPTION WHEN NO_DATA_FOUND THEN
V_IMAGE:=NULL;
V_FILENAME:=NULL;
WHEN OTHERS THEN
V_IMAGE:=NULL;
V_FILENAME:=NULL;
END;

IF V_IMAGE IS NOT NULL AND V_FILENAME IS NOT NULL THEN
SAVEFILE(V_IMAGE,'TEST',V_FILENAME);
insert into testt1 (DOCNO,DOCIMG, DOCDESC, FILE_NAME,FILE_MIMETYPE)
values (to_char(sysdate,'DDMMYYSS'),v_image,'Physical File ',V_filename,v_mime_type);
ELSE
APEX_ERROR.ADD_ERROR (
p_message => 'Image Not Upload',
p_display_location => apex_error.c_inline_in_notification );
END IF;
END;

3) Run the Page

















Comments

Popular posts from this blog

Telegram Integration with Oracle

The username or password for the connection pool named |apex||, are invalid, expired, or the account is locked

Enabled SQL Developer Web (SDW) & ORDS Database API ORDS 19.4