Download files in APEX

Download files in APEX short code.

begin
        sys.htp.init;
        sys.owa_util.mime_header( <MIME_TYPE>, FALSE );
        sys.htp.p('Content-length: ' || sys.dbms_lob.getlength( <BLOB_FILE>));
        sys.htp.p('Content-Disposition: attachment; filename="' || <FILE_NAME> || '"' );
        sys.htp.p('Cache-Control: max-age=3600');-- Cache hours
        sys.owa_util.http_header_close;
        sys.wpg_docload.download_file( <BLOB_FILE> );
     
        apex_application.stop_apex_engine;
end;