# Download Files in Oracle APEX Using the APEX_HTTP Package

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.

## **Downloading a blob (binary file) example**

```sql
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;
```

## **Downloading a clob (text file) example**  

```sql
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.
