Apex: BLOB direkt im Report anzeigen (alter Weg)

Um direkt im Report ein Bild (als BLOB in der Tabelle gespeichert) anzuzeigen sind folgende Schritte nötig:

1) Tabelle mit Blob-Spalte bauen:

CREATE TABLE UV_VERZEICHNIS
(
VERID NUMBER(14) NOT NULL,
PNR NUMBER(8),
VNAME VARCHAR2(100 CHAR),
NNAME VARCHAR2(100 CHAR),
BLOB_ID NUMBER,
BLOB_CONTENT BLOB,
BLOB_FILENAME VARCHAR2(4000 CHAR),
MIME_TYPE VARCHAR2(4000 CHAR),
CONSTRAINT UV_VERZEICHNIS_PK PRIMARY KEY (VERID)
);

2) PL-Proc zum Anzeigen des BLOB schreiben:

CREATE OR REPLACE procedure UNTERSCHRIFTEN.uv_blob_download
-- Purpose : Anzeige einer BLOB-Bild-Datei
(p_file in number)
as
v_mime varchar2(255);
v_length number;
v_file_name varchar2(2000);
Lob_loc BLOB;
BEGIN
select mime_type, blob_content, substr(blob_filename,
instr(blob_filename, '/') +1) ,dbms_lob.getlength(blob_content)
into v_mime,lob_loc,v_file_name,v_length
from uv_verzeichnis
where blob_id = p_file;
--
-- set up HTTP header
--
-- use an NVL around the mime type and
-- if it is a null set it to application/octect
-- application/octect may launch a download window from windows
owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );

-- set the size so the browser knows how much to download
htp.p('Content-length: ' v_length);
-- the filename will be used by the browser if the users does a save as
htp.p('Content-Disposition: filename="' v_file_name '"');
-- close the headers
owa_util.http_header_close;
-- download the BLOB
wpg_docload.download_file( Lob_loc );
end uv_blob_download;
/

3) In Apex eine Anwendung mit einer Reportseite bauen:
Select für diesen Report

SELECT verid, pnr, vname, nname, blob_id, blob_content, blob_filename,
mime_type
FROM uv_verzeichnis

4) Spaltendefinition für Anzeige der BLOB-Spalte:

Seite x -> Regions -> Report -> Column Attributes -> Edit-Button vor BLOB-Spalte -> Column Formatting: Hier im Feld „HTML Expression“ eintragen:

(Eckige Klammer nach link) img title="Bild" src="#OWNER#.uv_blob_download?p_file=#BLOB_ID#" width="300" height="100" /(Eckige Klammer nach rechts)

5) Alles bestätigen -> Report ist fertig!

6) Problem: Rechte zum Aufruf der Funktion uv_blob_download fehlen
-> Webserver-Fehler 403
-> Lösung: Anpassen der Funktion flows_030100.wwv_flow_epg_include_mod_local
(Flows_xxxxxx, wobei xxxxxx die ApEx-Version ist)

create or replace function flows_030100.wwv_flow_epg_include_mod_local(
procedure_name in varchar2)
return boolean
is
begin
-- Administrator note: the procedure_name input parameter may be in the format:
--
-- procedure
-- schema.procedure
-- package.procedure
-- schema.package.procedure
--
-- If the expected input parameter is a procedure name only, the IN list code shown below
-- can be modified to itemize the expected procedure names. Otherwise you must parse the
-- procedure_name parameter and replace the simple code below with code that will evaluate
-- all of the cases listed above.
--
if upper(procedure_name) in (
'UNTERSCHRIFTEN.UV_BLOB_DOWNLOAD') then
return TRUE;
else
return FALSE;
end if;
end wwv_flow_epg_include_mod_local;

Hier evtl. später noch weitere Funktionen eintragen!
Siehe auch http://daust.blogspot.com/2006/04/xe-calling-stored-procedures.html

Kommentare

Beliebte Posts aus diesem Blog

PGA unter Oracle 11g

trunc(sysdate) - nette Spiele mit dem Datum

Datapump - Verzeichnis erstellen