Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

No page error but also no image displayed on the report ?

zooidJun 26 2010 — edited Jun 28 2010
Hi Everyone,

First I like to apologise for the long post, but I would like to make sure that I am providing the full information so as not to waist anyone's time.

As I am having problems displaying images, in a report, but I am not getting any errors, all I see is the typical red X where the image shout be. When I right click the red X and select properties, it all appears to be fine:

http://127.0.0.1:8080/apex/ZOROPIO.FILE_TO_BLOB?p_file_id=6

except that Type: Not Available
and Size: Not Available

So I decided to creating a table and procedures to specifically test my approach and I am still getting the same result.

I have an Apex page where uses can upload an image to the system, using the following Page Process:

----------------------------------
On Submit - After Computations and validations

FOR REC IN( SELECT FILENAME, MIME_TYPE
FROM HTMLDB_APPLICATION_FILES
WHERE NAME = :P4_FILENAME
)
LOOP

INSERT INTO AB ( FNAME, MTYPE )
VALUES (REC.FILENAME, REC.MIME_TYPE);

END LOOP;

ZOROPIO.BLOB_TO_FILE(:P4_FILENAME);

DELETE FROM HTMLDB_APPLICATION_FILES
WHERE NAME = :P4_FILENAME;

----------------------------------
The AB table is define as:

CREATE TABLE "AB"
( "DB_ID" NUMBER NOT NULL ENABLE,
"FNAME" VARCHAR2(256 CHAR) NOT NULL ENABLE,
"A_IMG" BFILE,
"MTYPE" VARCHAR2(256 CHAR),
CONSTRAINT "AB_PK" PRIMARY KEY ("DB_ID") ENABLE
)
/

CREATE OR REPLACE TRIGGER "BI_AB"
BEFORE INSERT
ON ZOROPIO.AB
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW

DECLARE
tmpVar NUMBER;

BEGIN
tmpVar := 0;

SELECT NVL (MAX (DB_ID), 0) + 1 INTO tmpVar FROM AB;

:NEW.DB_ID := tmpVar;

IF :NEW.FNAME IS NOT NULL THEN

:NEW.A_IMG := BFILENAME ('IMG', :NEW.FNAME);

END IF;

END BI_AB;
/
ALTER TRIGGER "BI_AB" ENABLE
/

----------------------------------
The BLOB_TO_FILE procedure is defined as:

create or replace PROCEDURE BLOB_TO_FILE (p_file_name VARCHAR2) AS

l_out_file UTL_FILE.FILE_TYPE;
l_buffer RAW (32767);
l_amount BINARY_INTEGER := 32767;
l_pos INTEGER := 1;
l_blob_len INTEGER;
p_data BLOB;
file_name VARCHAR2 (256);

BEGIN

FOR rec IN (SELECT ID
FROM HTMLDB_APPLICATION_FILES
WHERE Name = p_file_name) LOOP

SELECT BLOB_CONTENT, filename
INTO p_data, file_name
FROM HTMLDB_APPLICATION_FILES
WHERE ID = rec.ID;


l_blob_len := DBMS_LOB.getlength (p_data);
l_out_file := UTL_FILE.fopen ( 'IMG',file_name, 'wb', 32767 );

--
WHILE l_pos < l_blob_len LOOP

DBMS_LOB.Read ( p_data,l_amount, l_pos, l_buffer );

IF l_buffer IS NOT NULL THEN

UTL_FILE.put_raw (l_out_file, l_buffer, TRUE);

END IF;

l_pos := l_pos + l_amount;

END LOOP;

--
UTL_FILE.fclose (l_out_file);

END LOOP;

EXCEPTION
WHEN OTHERS THEN

IF UTL_FILE.is_open (l_out_file) THEN

UTL_FILE.fclose (l_out_file);

END IF;

END BLOB_TO_FILE;

----------------------------------
This works fine, as I can see the data in both the OS Directory and the AB table after the user uplodas the image.


I have then define an Apex Report pageto display the uploaded images. The page has the following Source:

SELECT FNAME, MTYPE,
'<IMG SRC="ZOROPIO.FILE_TO_BLOB?p_file_id='||NVL( DB_ID, 0)||'"HEIGHT="'||80||'"WIDTH="'||100||'"/>' AS IMAGE
FROM ZOROPIO.AB

----------------------------------
The ZOROPIO.FILE_TO_BLOB procedure is defined as:

CREATE OR REPLACE PROCEDURE ZOROPIO.FILE_TO_BLOB ( p_file_id NUMBER ) IS

l_mime_type VARCHAR2 ( 256 );
l_file_name VARCHAR2 ( 256 );
l_bfile BFILE;
l_blob BLOB;
l_bfile_length NUMBER;
l_blob_length NUMBER;

BEGIN

SELECT FNAME, MTYPE
INTO l_file_name, l_mime_type
FROM AB
WHERE DB_ID = p_file_id;



l_bfile := BFILENAME ('IMG', l_file_name);

-- MAKE SURE THE FILE EXIST

IF ( DBMS_LOB.FILEEXISTS( l_bfile ) = 1 ) THEN

DBMS_LOB.CREATETEMPORARY ( l_blob, TRUE, DBMS_LOB.SESSION );

DBMS_LOB.FILEOPEN ( l_bfile );

l_bfile_length := DBMS_LOB.GETLENGTH ( l_bfile );

DBMS_LOB.LOADFROMFILE ( l_blob, l_bfile, l_bfile_length );

DBMS_LOB.FILECLOSE ( l_bfile );

l_blob_length := DBMS_LOB.GETLENGTH ( l_blob );

OWA_UTIL.MIME_HEADER( NVL ( l_mime_type, 'Application/Octet' ), FALSE );

HTP.P ( 'Content-length:' || l_blob_length );

OWA_UTIL.HTTP_HEADER_CLOSE;

WPG_DOCLOAD.DOWNLOAD_FILE ( l_blob );

DBMS_LOB.FREETEMPORARY( l_blob );
ELSE

RAISE_APPLICATION_ERROR(-20007, 'Requested IMG does not exist');

END IF;

END FILE_TO_BLOB;
/



I have GRANT EXECUTE to ZOROPIO for both the procedures:

BLOB_TO_FILE
FILE_TO_BLOB


----------------------------------
The Oracle database verison, Apex version, etc details are:


Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

Language: en-gb
Application Express 3.2.1.00.12


Any sugestions, help, etc would be much appreciated.

Thank you

Daniel
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 26 2010
Added on Jun 26 2010
3 comments
687 views