Hi,
I am working with APEX 5.1.
I am performing a test for downloading a PDF through the use of an APEX button.
I have a button, that when pressed, a page process is executed and a PDF file (originally stored in a table as BLOB) should be downloaded.
But it does not work.
The table has this structure:
SQL> desc temp_order_reports
Name Null? Type
----------------------------------------- -------- ----------------------------
SESSION_ID NUMBER
ORDER_ID NUMBER
ORDER_REPORT_NAME VARCHAR2(100)
ORDER_REPORT_LENGTH NUMBER
ORDER_REPORT BLOB
On the APEX Page Process page, the process triggered by the button is defined as:
begin
download_blob_as_pdf(pOrderID => 2);
end;
The table temp_order_reports is read for ORDER_ID=2, and are extracted:
- ORDER_REPORT_NAME=test.pdf
- ORDER_REPORT_LENGTH=13477581
- ORDER_REPORT -> is a BLOB that is the PDF file of Supplied_Packages.pdf
The column SESSION_ID is not used at all at that moment.
The download_blob_as_pdf procedure is as follow:
create or replace procedure download_blob_as_pdf
(
pOrderID number
)
is
v_mime varchar2(48);
v_length number(38);
v_file_name varchar2(100);
v_blob blob;
begin
dbms_lob.createtemporary(v_blob,true);
select
'application/pdf' as mimetype,
order_report_length,
order_report_name,
order_report
into
v_mime,
v_length,
v_file_name,
v_blob
from
temp_order_reports
where
order_id = pOrderID;
sys.htp.init;
dbms_output.put_line('[1]');
sys.owa_util.mime_header(ccontent_type => v_mime, bclose_header => FALSE );
dbms_output.put_line('[2]');
sys.htp.p('Content-length: ' || sys.dbms_lob.getlength(v_blob));
sys.htp.p('Content-Disposition: attachment; filename="' || v_file_name || '"' );
sys.htp.p('Cache-Control: max-age=30'); -- tell the browser to cache for 30 sec
sys.owa_util.http_header_close;
sys.wpg_docload.download_file(v_blob);
apex_application.stop_apex_engine;
exception
when others then
raise;
end;
Through APEX, I get the error:
=> Error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
I run this procedure through SQL*Plus:
SQL> begin
download_blob_as_pdf(pOrderID => 2);
end; 2 3
4 /
[1]
begin
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "TOPAZ.DOWNLOAD_BLOB_AS_PDF", line 41
ORA-06512: at line 2
=> PL/SQL: numeric or value error
Does someone know what can be wrong in the above code?
Thanks by advance for any tip(s).
Kind Regards