Database

Get Involved. Join the Conversation.

Topic

    Cesar Tepetla Corte
    compress multiple files using APEX_ZIP
    Topic posted August 13, 2019 by Cesar Tepetla CorteBronze Medal: 1,250+ Points, tagged Apex, DBaaS 
    32 Views, 4 Comments
    Title:
    compress multiple files using APEX_ZIP
    Summary:
    compress multiple files using APEX_ZIP
    Content:

    Hi everyone,

    I am trying to zip the contents of a table where I use four fields.

    My code gives an error when trying to compile it:

    CREATE OR REPLACE PROCEDURE ZIP_IMPORT_WPI_FILES
    AS
    l_zip_file blob;
    BEGIN
        FOR f IN (SELECT METADATA_NAME, METADA, IMAGE_NAME, IMAGE FROM FILES_PI)
        LOOP
           apex_zip.add_file (
                p_zipped_blob => l_zip_file,
                p_file_name   => f.IMAGE_NAME,
                p_content     => f.IMAGE );
           
           apex_zip.add_file (
                p_zipped_blob => l_zip_file,
                p_file_name   => f.METADATA_NAME,
                p_content     => f.METADA);
        END LOOP;
     
    apex_zip.finish (p_zipped_blob => l_zip_file);
    END;
    PL / SQL: Statement ignored
    PLS-00306: number or types of wrong arguments when calling 'ADD_FILE'
     
    What is the correct way to compress several files?
     
     

    Comment

     

    • Vladislav Uvarov

      What is the data type of FILES_PI.IMAGE and FILES_PI.METADA columns? APEX_ZIP.ADD_FILE only supports the BLOB data type for P_CONTENT parameter. If your data is not stored in the table as BLOB, you need to convert it first inside your FOR loop.

    • Vladislav Uvarov

      There should be no problem invoking APEX_ZIP.ADD_FILE multiple times. This would certainly not result in a compilation-time error. When I create FILES_PI table as below, I am able to successfully compile ZIP_IMPORT_WPI_FILES procedure as you provided it in my APEX 19.1 environment.

      create table FILES_PI (metadata_name varchar2(30), metada blob, image_name varchar2(30), image blob);
      
    • Cesar Tepetla Corte

      I'll go check it out and come back with the comments.
      Thank you