Download One Or More Files
1. Create a process
declare
var_zip blob;begin-- Create/clear the ZIP collectionapex_collection.create_or_truncate_collection(p_collection_name => 'ZIP');for i in 1..apex_application.g_f01.countloop-- Loop through all the files in the databasebeginfor var_file in (select file_name, blob_contentfrom moviewhere 1=1and file_name is not nulland id = apex_application.g_f01(i))loop-- Add each file to the var_zip fileapex_zip.add_file (p_zipped_blob => var_zip,p_file_name => var_file.file_name,p_content => var_file.blob_content );end loop;exception when no_data_found then-- If there are no files in the database, handle errorraise_application_error(-20001, 'No Files found!');end;end loop;-- Finish creating the zip file (var_zip)apex_zip.finish(p_zipped_blob => var_zip);-- Add var_zip to the blob column of the ZIP collectionapex_collection.add_member(p_collection_name => 'ZIP',p_blob001 => var_zip);end;
2. Createa Ajax Call Back process and call it as download_zip_file
declarevar_mimetype varchar2(50) := 'application/zip';var_name varchar2(100) := to_char(current_date, 'DD-MON-YYYY') || '_files_by_project.zip';var_blob blob;begin-- Get the BLOB from the ZIP collectionselect blob001 into var_blob from apex_collections where collection_name = 'ZIP' and seq_id = 1;sys.htp.init;sys.owa_util.mime_header( var_mimetype, FALSE );sys.htp.p('Content-length: ' || sys.dbms_lob.getlength( var_blob));sys.htp.p('Content-Disposition: attachment; filename="' || var_name || '"' );sys.htp.p('Cache-Control: max-age=3600'); -- tell the browser to cache for one hour, adjust as necessarysys.owa_util.http_header_close;sys.wpg_docload.download_file( var_blob );apex_application.stop_apex_engine;exception when apex_application.e_stop_apex_engine thenNULL;end;
3. Create a Branch after processing
Then Enjoy
