Skip to Main Content
Custom Confirm Dialog Button Labels Export Application

Download Static Files

How to download static files from APEX

Example

DECLARE
    v_file_name      VARCHAR2(255);
    v_mime_type      VARCHAR2(255);
    v_file_content   BLOB;
BEGIN
    SELECT
        file_name,
        mime_type,
        file_content
    INTO
        v_file_name,
        v_mime_type,
        v_file_content
    FROM
        APEX_APPLICATION_STATIC_FILES
    WHERE
            application_id = <value>
        AND file_name      = '<value>';

    IF v_file_name IS NOT NULL THEN
       sys.htp.init;
       sys.owa_util.mime_header( v_mime_type, FALSE );
       sys.htp.p('Content-Length: ' || dbms_lob.getlength( v_file_content)  );
       sys.htp.p('Content-Disposition: filename="' || v_file_name || '"');
       sys.owa_util.http_header_close;
       sys.wpg_docload.download_file( v_file_content );
       apex_application.stop_apex_engine;
    END IF;

    EXCEPTION
       WHEN apex_application.stop_apex_engine THEN
       NULL;
       WHEN OTHERS THEN
       NULL ;

END;