So, I'm currently trying to download an xml file stored in an Oracle table with a link I created for an Oracle Apex page. Here's the setup:
The table can contain 2 different files for xml stored as blob. With that I'm trying to have a report on Oracle Apex with a link to download these blobs, one for each type of file for every line of data.
The query I have to set up the links is the following:
select max(case when a.filename like 'TYPE1%' then dbms_lob.getlength(a.upload_file) else null end) as upload_type1,
max(case when a.filename like 'TYPE2%' then dbms_lob.getlength(a.upload_file) else null end) as upload_type2
from blob_table a;
Now the page report should have 2 columns with a different link to each one, set to the size of each one of these. The links themselves are set to the same page using "Type1" and "Type2" respectively as a request, which are meant to trigger the following PLSQL function to download the files:
declare
l_blob_content blob_table.upload_file%TYPE;
l_mime_type varchar2(20);
l_id number;
l_filename varchar2(255);
begin
select id
into l_id
from blob_table
where file_id = :FILE_ID
and filename like 'TYPE1%';
select upload_file
,'text/xml',
filename
into l_blob_content,
l_mime_type,
l_filename
from blob_table
where id = l_id;
sys.HTP.init;
sys.OWA_UTIL.mime_header(l_mime_type, FALSE, 'UTF-8');
sys.HTP.p('Content-Length: ' || DBMS_LOB.getlength(l_blob_content));
sys.HTP.p('Content-Disposition: filename="' || l_filename || '"');
sys.OWA_UTIL.http_header_close;
sys.WPG_DOCLOAD.download_file(l_blob_content);
apex_application.stop_apex_engine;
exception when apex_application.e_stop_apex_engine then
null;
when others then
HTP.p('Something wrong');
end;
So far from what I've seen when searching this functionality, it all seems in place. The message I get however when clicking the link and trying to download it is this:
At first I thought I had something wrong and also tested the mime_type as "application/xml", and the file is shown in the page in an HTML format. Any ideas why the "text/xml" is giving an encoding error? Does it have to do with the 3rd input value for the mime_type?
