Here I am giving an example to to read and store all files contained in the ZIP into oracle table using a simple oracle APEX API.
APEX_ZIP: This package manages the zipping and unzipping of files.
Data Types
The data types used by the APEX_ZIP package are described in this section.
t_files
type t_files is table of varchar2 (32767) index by binary_integer;
----------------------------------------------------------------------------------------------------------------------------
GET_FILE_CONTENT Function
This function returns the BLOB of a file contained in a provided zip file.
Syntax:
----------------------------------------------------------------------------------------------------------------------------
GET_FILES Function
This function returns an array of file names, including the path, of a provided zip file that contains a BLOB.
Syntax:
----------------------------------------------------------------------------------------------------------------------------
Step 1: Create a table fxgn_zip_files, which will be used to store ZIP files.
CREATE SEQUENCE fxgn_zip_files_s START WITH 1 INCREMENT BY 1;
Step 2: Create a table fxgn_files, which will be used to store all files contained in a ZIP file.
Step 3: Create a new blank page.
Note: Mine was page 17. You will need to update reference to "P17" with your page number if it's different.
Step 4: Create a new HTML region to the page.
Step 5: Create a new item to the region. Set name to P17_FILE_UPLOAD and change the type File Browser.
Step 6: Create two new buttons. Set name to ZIP_UPLOAD, EXTRACT_FILES and leave the action default of Submit Page and set server side condition Never.
Step 7: Create a PLSQL process with below script, it should be executed when you click ZIP_UPLOAD button and set name to Upload Files.
Step 8: Create a new dynamic action that fires when the file is upload. The easiest way to do this is to right click the button and select Create Dynamic Action Set name to Upload ZIP File
Step 9: After the file is uploaded, same would be reflecting in fxgn_zip_files table. Post the upload the same will be reflecting in Zipped Files (classical report) section. Create classical report to show uploaded ZIP files as below,
Step 11: Create a PLSQL process with below script, it should be executed when you click EXTRACT_FILES button and set name to Extract Files.
Step 12: Create a new item to the region. Set name to P17_FILE_ID and change the type Hidden.
Step 13: Read a zip file from a fxgn_zip_files table, extracting it and storing all files of the zip file into fxgn_files.
Change UNZIP column type to Link and Set target type URL and copy and paste below JS code in URL section as below, (zipped files - classical report)
URL: javascript:$s('P17_FILE_ID','#FILE_ID#'); javascript:apex.confirm ('Are you sure you want to extract files from this folder?', 'EXTRACT_FILES');
Step 14: After the file is extracted, same would be reflecting in fxgn_files table. Post the upload the same will be reflecting in Extracted Zip Files (classical report) section. Create classical report to show all the extracted files in a provided zip file as below,
Step 15: Provide option to view extracted files by clicking on the report (extracted zip files) attribute File. [Optional]
The demo is here.
Review Mechanism:
Step 1: Select a file/Drag and drop the file from the location.
Comments
Post a Comment