# The 🆕 Way to In-Line Files with APEX

# Introduction

I love finding new ways to do things in APEX. Recently, I was required to do an in-line preview of PDF files for an Archival system file I was working on. I started using my previous approach of an iframe and remembered that APEX 24.1 introduced [Declarative File Download Support](https://apex.oracle.com/en/platform/features/whats-new-241/). Maybe I could use that to do an in-line preview?

<div data-node-type="callout">
<div data-node-type="callout-emoji">👉</div>
<div data-node-type="callout-text">In this post, I will show you how to preview files in the browser with just an SQL statement!</div>
</div>

# Declarative File Download

The requirement was to allow users to download or in-line preview attachments for archived invoices. Using the APEX Content row Region type, I built a nice UI to show available attachments.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1742648928519/6482fd0b-db96-441d-92a5-820c68117e90.gif align="center")

## Download

The Action for the download icon populates a page item `P12_DL_FILE_ID` with the ID of the selected file.

![Oracle APEX Declarative File Download Action](https://cdn.hashnode.com/res/hashnode/image/upload/v1742649114612/3635b50f-28a9-4583-bb15-8b9db6506beb.png align="center")

Page Item `P12_DL_FILE_ID` has a dynamic action with an Action of ‘Download’:

![Oracle APEX Declarative File Download Action Dynamic Action](https://cdn.hashnode.com/res/hashnode/image/upload/v1742649390861/0fafe042-390e-471d-8b79-ee57284ec6ae.png align="center")

* View File As ‘Attachment’ causes the file to be downloaded.
    
* If you select ‘Multiple Files’, files are exported as a zip file.
    
* The SQL query must have three specific columns: the file BLOB content, the file name,,, and the file mime type.
    
* In my example, the files are stored in Oracle OCI Object Storage. The function `oci_utl_pk.get_file` fetches the file from Object Storage and returns the BLOB content.
    

## In-Line Preview

We need to create a new modal page to get an in-line preview. The drawer style is quite effective, especially for PDF files, as it shows the document on a full-height modal page.

![Oracle APEX File In-Line Modal Page](https://cdn.hashnode.com/res/hashnode/image/upload/v1742649752137/2ffc4d4b-b5b4-4064-a443-b71df9c84bb9.png align="center")

Create a page item with a dynamic action:

![Oracle APEX File In-Line Dynamic Action](https://cdn.hashnode.com/res/hashnode/image/upload/v1742649899976/16f3902e-8922-4b65-a6c3-45fb435e53d6.png align="center")

* Use the ‘Download’ action again.
    
* This time, choose ‘Inline’ for ‘View File As’ property.
    
* The SQL query does not change.
    
* Ensure that the dynamic action is fired on initialization so the file is loaded as soon as the modal opens.
    

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">If the file cannot be viewed in-line in the browser, e.g., ZIP, Word, Excel, or PowerPoint, APEX will download it instead of displaying it in-line.</div>
</div>

# Conclusion

Sometimes, it is the small things that make our lives easier as developers. One of those things is downloading and previewing files in line with just an SQL statement!
