How to Zip and download files in Oracle APEX?

How to Zip and download files in Oracle APEX?

Using the APEX_ZIP utility package

Apr 9, 2023·

2 min read

Play this article


In this tutorial, we will be focusing on how to use the apex_zip utility package to zip files and enable them to be downloaded with just a single button click from within an Oracle APEX page.


In the employee self-service portal, employees frequently request reimbursements for various expenses such as travel allowances, shift allowances, phone reimbursements, and more. To process these requests, employees are required to upload digital copies of their supporting documents to the portal. At the end of each month, the HR admin is responsible for downloading these requests and submitting them to the accounts team. However, this process can be quite time-consuming, especially when it comes to downloading multiple attachments. To simplify this process, we've created a solution that allows users to download all attachments for all requests submitted by employees during a specific period as a single zip file. To learn more about how this solution works, please watch the video provided below.


To create a functionality to download attachments as a zip file, follow these steps:

  1. Create an application process named DOWNLOAD_ATTACHMENTS in the Shared Components or at the page level in the Ajax Callback section.

        l_download_file_name  VARCHAR2(64) := '';
        l_zip_file        BLOB;
        l_disposition     VARCHAR2(30) := 'attachment';
        FOR i IN (
           SELECT file_name,
           FROM my_files
        ) LOOP
          -- Add files to the zip 
                            p_zipped_blob => l_zip_file
                          , p_file_name => i.file_name
                          , p_content => i.file_content
        END LOOP;
        -- Finish zipping
        apex_zip.finish(p_zipped_blob => l_zip_file);
        -- Download zip file
                              , false
        sys.htp.p('Content-length: '
                  || sys.dbms_lob.getlength(l_zip_file));
        sys.htp.p('Content-Disposition: attachment; filename="'
                  || l_download_file_name
                  || '"');
  2. Create a button and set the behavior to "Submit Page".

  3. Under the processing tab, create a branch after the submit (or after processing) and set the behavior to:

    • Type: Page or URL (Redirect)

    • Target: Same page


  4. Save and run the application.


Did you find this article valuable?

Support Arun Mohan by becoming a sponsor. Any amount is appreciated!