Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Download plain/text CLOB contain

HansMueller69May 25 2025 — edited May 25 2025

Hello,

I followed the description of the file download of this site - APEX Version: 23.2.5 :

https://oracle-base.com/articles/misc/apex-tips-file-download-from-a-button-or-link

CREATE TABLE APEX_LRD.APEX_LRD_FILE_TEMPLATES 
( id_apex_lrd_file_templates      NUMBER(18)
, x_file_name                     VARCHAR2(500)
, l_template                      CLOB
, c_mime_type                     VARCHAR2(100)
)
TABLESPACE APEX_DATA;
INSERT INTO APEX_LRD.APEX_LRD_FILE_TEMPLATES
(id_apex_lrd_file_templates, x_file_name, l_template, c_mime_type)
VALUES
(fu_gettechkey, 'BDA_TEST.csv', 'First
Second
Third'
, 'text/plain');
CREATE OR REPLACE PROCEDURE APEX_LRD.PR_GET_FILE_TO_DOWNLOAD
(p_file_name  IN VARCHAR2)
IS
 v_template      CLOB;
v_template_blob BLOB;
 v_mime_type     VARCHAR2(500);
BEGIN
 SELECT l_template,
        c_mime_type
 INTO   v_template,
        v_mime_type
 FROM   APEX_LRD.APEX_LRD_FILE_TEMPLATES 
 WHERE  x_file_name = p_file_name;
v_template_blob := apex_util.clob_to_blob(
   p_clob => v_template,
   p_charset => 'AL32UTF8' );
 SYS.HTP.INIT;
 SYS.OWA_UTIL.MIME_HEADER(v_mime_type, FALSE);
 SYS.HTP.P('Content-Length: ' || DBMS_LOB.GETLENGTH(v_template_blob));
 SYS.HTP.P('Content-Disposition: filename="' || p_file_name || '"');
 SYS.OWA_UTIL.HTTP_HEADER_CLOSE;
 SYS.WPG_DOCLOAD.DOWNLOAD_FILE(v_template_blob);
 apex_application.stop_apex_engine;
EXCEPTION
 WHEN apex_application.e_stop_apex_engine THEN
   NULL;
 WHEN OTHERS THEN
   HTP.P('Whoops');
END;
/

It works somehow but it opens a new site in spite of downloading the file.. .

What can be the problem? Thanks

I want to initiate the download from the Upload site:

maybe this is the reason?

Redirect to Url:

f?p=&APP_ID.:1:&APP_SESSION.:APPLICATION_PROCESS=PR_GET_FILE_TO_DOWNLOAD:::APP_FILE_NAME_TO_DOWNLOAD:BDA_TEST.csv

This post has been answered by HansMueller69 on May 25 2025
Jump to Answer
Comments
Post Details
Added on May 25 2025
1 comment
145 views