I have requirement in which on clicking filename , I would be able to download it from apex app. I am able to display it but it is not getting downloaded.
I am using below code to display and download the file. It is displaying correct data , mime_type value is correct – text/csv.
DECLARE
l_blob BLOB;
l_length NUMBER;
l_mime_type VARCHAR2(50);
l_file_name VARCHAR2(255);
BEGIN
-- Retrieve file details from the database
SELECT filecontent, filetype, filename
INTO l_blob, l_mime_type, l_file_name
FROM file_ingestion
WHERE file_id =:P0_ID; -- Use the correct page item
-- Set the response headers for file download
owa_util.mime_header(l_mime_type, FALSE); -- Set MIME type
--htp.p('Content-Length: ' || dbms_lob.getlength(l_blob)); -- Set file size
htp.p('Content-Disposition: attachment; filename="' || l_file_name || '"'); -- Set filename and prompt download
owa_util.http_header_close;
-- Output the file content
wpg_docload.download_file(l_blob);
EXCEPTION
WHEN OTHERS THEN
htp.p('An error occurred: ' || SQLERRM);
END;
More context –
I have an apex interactive report which displays all the files stored in file ingestion table. This report has a link attribute set on filename which will be redirecting it to the another page in application called – download and will take p0-id as file id which is the unique key of the table as well. Now in download page , in region I am selecting type as dynamic content and then the mentioned pl/SQL code.
2
No need to write a page process for this. Check the API APEX_UTIL.GET_BLOG_FILE_SRC to generate a link that downloads the file. For an example (report), install the sample app “Sample File Upload and Download” from the Gallery.
4