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. Maybe I could use that to do an in-line preview?
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.
Download
The Action for the download icon populates a page item P12_DL_FILE_ID
with the ID of the selected file.
Page Item P12_DL_FILE_ID
has a dynamic action with an Action of ‘Download’:
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.
Create a page item with a dynamic action:
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.
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!
Subscribe to my newsletter
Read articles from Jon Dixon directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Jon Dixon
Jon Dixon
Hi, thanks for stopping by! I am focused on designing and building innovative solutions using the Oracle Database, Oracle APEX, and Oracle REST Data Services (ORDS). I hope you enjoy my blog.