Download Files in Oracle APEX Using the APEX_HTTP Package

Search for a command to run...

No comments yet. Be the first to comment.
Oracle APEX already includes Font APEX as the default icon library for Universal Theme. In most cases, that is enough. But in one of my APEX apps, I needed a few icons that were not available there, s

Looking to give your Oracle APEX mobile app a modern, native feel? Here’s a quick hack: add a floating action button that stays anchored at the bottom corner just like in popular mobile apps. This sma

APEX 26.1 has been updated to the Universal Theme. While much of the attention in this release is on AI features, I think the UT improvements are just as important for developers like me who care abou

The apex_barcode package offers a PL/SQL API to generate various types of barcodes. You can output barcodes as SVG (Scalable Vector Graphics) values or as PNG file blobs, making it easy to embed them

Oracle APEX makes it easy to get data on screen fast, but often, the default tabular output isn’t enough. What if you want to highlight statuses, add icons, or display badges all without writing compl

File downloads are a common requirement in Oracle APEX apps, whether you’re letting users export reports, download images, or retrieve documents stored in the database. With APEX 24.2, the apex_http package provides a simple, modern API for downloading both BLOB and CLOB content, making file delivery more straightforward than ever.
The apex_http package offers PL/SQL procedures to send files (BLOBs or CLOBs) directly to the client browser for download. It handles MIME types, filenames, and ensures the download process is clean by clearing previous output buffers and stopping the APEX engine after the file is sent.
declare
l_file blob;
l_content_type varchar2(4000);
l_filename varchar2(4000);
begin
select blob_content, mime_type, filename
into l_file, l_content_type, l_filename
from apex_application_temp_files
where name = :p1_file;
apex_http.download(
p_blob => l_file,
p_content_type => l_content_type,
p_filename => l_filename
);
end;
declare
l_text clob;
begin
l_text := 'APEX BLOG';
apex_http.download(
p_clob => l_text,
p_content_type => 'text/plain',
p_filename => 'mytext.txt'
);
end;
When you call apex_http.download, it clears any previous output buffer, ensuring that only the intended file is delivered to the user and no other content is included. After the file download is initiated, the procedure automatically calls apex_application.stop_apex_engine, which cleanly ends the page process and prevents further processing or output.
Starting with APEX 24.1, there is also support for a "download" dynamic action, making it even easier to trigger file downloads directly from the user interface without writing custom PL/SQL code. Additionally, you can control whether the file opens directly in the browser or is downloaded as an attachment by using the p_is_inline parameter setting it to true opens the file inline, while false prompts a download.