Press "Enter" to skip to content

Display BLOB Contents (PDF, Images) into a Region in Oracle Apex Page

Here I am giving an example to display BLOB contents (PDF, Images) into a region in Oracle Apex page.

Suppose you have an employee screen and whenever the user opens that screen to edit or view record, you want to display employee’s payslip whether it is in image format or in PDF format. To perform this task, follow the below steps:

  1. First of all, you need a table in which you want to store the BLOB content and the structure of that table should be as follows:
CREATE TABLE EMP_PAYSLIPS 
   (EMPNO NUMBER, 
  FILENAME VARCHAR2(200), 
  REPORT BLOB, 
  MIMETYPE VARCHAR2(100), 
  CREATED_DATE DATE, 
  CREATED_BY VARCHAR2(100)
   );

ALTER TABLE EMP_PAYSLIPS ADD CONSTRAINT PK_EMPPAYSLIPS
PRIMARY KEY (EMPNO);

Note: The column MIMETYPE has an important role here. Whenever you store a PDF in the BLOB data, the MIMETYPE should be application/pdf and if storing images then MIMETYPE should be image/jpeg.

Also, please check my previous post, in which I have given an example to load PDF files into a BLOB field in Oracle Apex.

  1. Now I am assuming that you have data in the above table.
  2. Now in Oracle Apex, click on the Shared Components > Application Process and click the Create button to create an Application Process. The screen will popup as shown in the below image.

Create Application Process in Oracle Apex

  1. Specify a name in the Name field and for Point select Ajax Callback: Run this application process when requested by a page process option. Then click on the Next button.
  2. On the next step, add the following PL/SQL code in the PL/SQL code section as shown in the below:
DECLARE
  vBlob blob;
  vmimetype varchar2(50);
BEGIN
  SELECT report, mimetype INTO vBlob, vmimetype
                FROM emp_payslips
                WHERE empno = V('P3_EMPNO');
                 
  owa_util.mime_header(vmimetype,false);
  htp.p('Content-Length: ' || dbms_lob.getlength(vBlob)); 
  owa_util.http_header_close;  
  wpg_docload.download_file(vBlob);
  exception 
  when no_data_found then
   null;
END;

PL/SQL code application process.

  1. Then click on the Next button and on another screen just click on the Finish button to create the Application Process.
  2. Now open the Page in Oracle Apex in which you want to display the BLOB contents.
  3. Create a new Region and set the type as Static content and put the following code into the Text source, as shown in the below image:
<p align="center">
<iframe src="f?p=&APP_ID.:0:&SESSION.:APPLICATION_PROCESS=display_emp_blob:NO::P3_EMPNO,&P3_EMPNO." width="99%" height="1000">
</iframe>
</p>

Oracle Apex - Static Region

You can notice in the above code that we are calling the Application Process display_emp_blob we just created, using the Apex URL format.

Save the changes and run the page to test. Whenever you will open the Employee screen in Edit mode BLOB data will display in the region, whether it is an image or a PDF file.

See also:

Have you found the answer to your question? If not, you can discuss it with me in the comments section below or join my Q&A community OrclQA.com for developers and ask your question. It is FREE.

Vinish Kapoor

Follow

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

guest
9 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Gabriel
Gabriel
5 months ago

Hey man, nice post. But how can you do it passing parameters?

Rajko
Rajko
4 months ago

I have a problem with mozzila, It starts automatticlly do download content from iframe, have you any sollution. Chrome works fine…..

Rajko
Rajko
Reply to  Rajko
4 months ago

I have change it from iframe to embeded tags and it works…

Roberto Parraga
Roberto Parraga
3 months ago
Hello, the post is very good, but in my case it does not show the content of PDF Blob. Show only HTML code in my static region:

<p align=”center”> <iframe src=”javascript:apex.navigation.dialog.close(false,’/ords/r/r2vm_notaria_digital/notaria-digital/0?request=APPLICATION_PROCESS%3DDISPLAY_ESCRITURA_BLOB&session=16229955116938′);” width=”99%” height=”1000″> </iframe></p>

Giulio
Giulio
3 months ago

Hi,
thanks for the post, it’s very useful. I’m trying to create it under Apex 20.1 version and the page shows the error “Process show_stored_search not found.” where show_stored_search is the Ajax process.
Could you help me?
Thanks

Raghuraman
Raghuraman
Reply to  Vinish Kapoor
1 month ago

Facing Same issue. Process name matches all lower case as defined

SIRIMEVAN RANASINGHE
SIRIMEVAN RANASINGHE
1 month ago

HI, I have a requirement to open BLOB files which are stored in DB. But there is no mime type define in that table. I was wondering if there is any way to have the browser correctly download BLOB content without knowing the MIME-TYPE and show the file ? Many thanks in advance.