1. Introduction
Welcome to a new blog post. In this post, I will show you how to display an image in a report within Oracle APEX after uploading images to an existing table. Additionally, I will add a button that, when clicked, will display the image in a modal page within the browser. Furthermore, I will add another button in the report that allows downloading the respective image. I will show you how all of this works step by step.
2. Preparing the Table
If you already have a table, you can start with that. Otherwise, you can use the
Department
table for testing.2.1. Creating the Sequence and Table
Here is the code to create the
Department
table. First, a sequence is created, and then the table.Explanation:
- Sequence: A sequence is created to generate unique
depa_id
values. - Table: The
apno_department
table is created to store department information. It includes columns for department ID, name, location, image (as BLOB), image name, image MIME type, and some audit fields.
2.2. Inserting Records
Next, we will insert some records into the
Department
table.Explanation:
- Records: Example records are inserted into the
apno_department
table to represent various departments with their locations.
3. Creating a Report and Form
Create a report to display all
Department
entries and a form page to add new Department
entries or edit existing ones and upload images.3.1. Creating the Report
Navigate to the Oracle APEX Page Designer and create a new report based on the
apno_department
table.- Report Type: Interactive Report
- SQL Query:
Explanation:
- Interactive Report: Allows users to browse, filter, and sort the data.
- SQL Query: Retrieves all relevant information from the
apno_department
table.
3.2. Creating the Form
Create a form page to add new departments or edit existing ones.
- Form Type: Form on a Table with Report
- Table:
apno_department
Explanation:
- Form: Allows users to create, update, or delete data in the
apno_department
table.
4. Creating a Procedure
The next step is to create a procedure to download or preview files.
Explanation:
- pi_primary_ID: The primary ID of the file to be downloaded or previewed.
- pi_view_type: The type of view, 'D' for download and 'P' for preview.
- v_blob_content: Variable to store the binary content of the file.
- v_mime_type: Variable to store the MIME type of the file.
- v_filename: Variable to store the file name.
- v_check_data_in_db: Variable to check if the file exists in the database.
The procedure first checks if the file exists in the database. If the file exists, it retrieves the file content, name, and MIME type. Based on the
pi_view_type
parameter, it either downloads the file or previews it inline.5. Creating Application Items
We need to create two application items to store the file ID and view type. These items will be used to pass parameters to the
pr_download_file
procedure.- P_DOWNLOAD_FILE_ID: Stores the ID of the file to be downloaded or previewed.
- P_DOWNLOAD_TYPE: Stores the type of view, 'D' for download and 'P' for preview.
6. Creating an Application Process
Create an application process that calls the
pr_download_file
procedure. This process will be executed when the user clicks on the download or preview link.Explanation:
- :P_DOWNLOAD_FILE_ID: The ID of the file to be downloaded or previewed.
- :P_DOWNLOAD_TYPE: The type of view, 'D' for download and 'P' for preview.
7. Creating an Oracle APEX Page
Navigate to the Oracle APEX Page Designer to create a report based on the
file_uploads
table and a form to upload various files. Make sure to upload some files initially so that your table has data for testing purposes.Additionally, create another page as a modal drawer. This drawer page will be used to preview any data when the user clicks on a preview link.
In the report, create columns for file preview and download. For the download column, set the link to trigger the download process without redirecting the page. For the preview column, set the link to open the modal drawer page, allowing the user to view the file.
You will need to set two application items to link the file ID and the view type (P for preview, D for download). Also, configure the application process accordingly.
8. Creating a Report with SQL Statement
Create a report with the following SQL statement to display the report on the Oracle APEX page.
Button HTML:
Explanation:
- Button HTML: Adds download and preview buttons to the report when an image is present.
9. Adding Custom CSS (Optional)
Add the following CSS to the Oracle APEX page and assign the report a static ID:
Department_Report
. This will ensure that only images in the report are displayed smaller.Custom CSS:
Explanation:
- CSS: Ensures that images in the report are displayed smaller and round.
10. Configuring the Preview and Download Columns
To allow users to preview and download files directly from the report, you need to add two columns with links for these actions. Follow these steps to set it up:
10.1. Preview Column
- Add a new column to your report.
- Set the column type to "Link".
- Configure the link to set the application item
P_DOWNLOAD_FILE_ID
to the file ID andP_DOWNLOAD_TYPE
to 'P'. - Set the target to the modal drawer page.
10.2. Download Column
- Add another new column to your report.
- Set the column type to "Link".
- Configure the link to set the application item
P_DOWNLOAD_FILE_ID
to the file ID andP_DOWNLOAD_TYPE
to 'D'. - Set the target to the current page to avoid redirection.
Explanation:
- Preview Column: When the user clicks on this link, the file will be previewed in the browser using the modal drawer.
- Download Column: When the user clicks on this link, the file will be downloaded directly.
11. Supported File Formats for Preview in Chrome
Here is a list of file formats that can be uploaded and previewed directly in Chrome:
Text-Based Formats
- HTML (.html, .htm): HyperText Markup Language files.
- Text (.txt): Plain text files.
- JavaScript (.js): JavaScript files.
- CSS (.css): Cascading Style Sheets files.
- CSV (.csv): Comma-separated values files.
- JSON (.json): JavaScript Object Notation files.
Image Formats
- JPEG (.jpeg, .jpg): Joint Photographic Experts Group files.
- PNG (.png): Portable Network Graphics files.
- GIF (.gif): Graphics Interchange Format files.
- SVG (.svg): Scalable Vector Graphics files.
- WebP (.webp): Web Picture format files.
Video Formats
- MP4 (.mp4): MPEG-4 Part 14 files.
- WebM (.webm): Web Media files.
- Ogg (.ogg): Ogg multimedia files.
Audio Formats
- MP3 (.mp3): MPEG-1 Audio Layer III files.
- WAV (.wav): Waveform Audio File Format files.
- Ogg (.ogg): Ogg Vorbis audio files.
Document Formats
- PDF (.pdf): Portable Document Format files.
- Microsoft Word (.doc, .docx): Microsoft Word document files.
- Microsoft Excel (.xls, .xlsx): Microsoft Excel spreadsheet files.
- Microsoft PowerPoint (.ppt, .pptx): Microsoft PowerPoint presentation files.
For other file types, the default behavior will be to download the file.
12. Implementing Bulk Download Functionality
To allow users to download all files at once, you can create a button that triggers a dynamic action to initiate a bulk download. This feature is available starting from Oracle APEX 24.1. When the button is clicked, all files specified in the SQL query will be zipped and offered as a single download.
Creating the Bulk Download Button
- Add a Button:
- Go to the Page Designer and add a new button to your report page.
- Label the button as "Download All Files".
Configuring the Dynamic Action
- Create a new dynamic action for the button click event.
- Set the action to "Download".
- Use the following PL/SQL code to fetch all files and zip them:
Explanation:
- The dynamic action will execute the PL/SQL code to fetch all files from the
file_uploads
table. - The files will be zipped and offered as a single download.
13. Conclusion
By following these steps, you can easily set up a system in Oracle APEX to preview or download files. This setup ensures that users have a seamless experience when interacting with files in your application. Whether it's text files, images, videos, or documents, Oracle APEX makes it easy to manage and display files.
I hope this guide helps you extend your Oracle APEX application. Good luck!
{fullWidth}
0 $type={blogger}:
Kommentar veröffentlichen