GET_BLOB_FILE_SRC Function

As an alternative to using the built-in methods of providing a download link, you can use the APEX_UTIL.GET_BLOB_FILE_SRC function. One advantage of this approach, is the ability to more specifically format the display of the image (with height and width tags). Please note that this approach is only valid if called from a valid Oracle Application Express session. Also, this method requires that the parameters that describe the BLOB to be listed as the format of a valid item within the application. That item is then referenced by the function.

Syntax

FUNCTION GET_BLOB_FILE_SRC (
    p_item_name           IN VARCHAR2 DEFAULT NULL,
    p_v1                  IN VARCHAR2 DEFAULT NULL,
    p_v2                  IN VARCHAR2 DEFAULT NULL,
    p_content_disposition IN VARCHAR2 DEFAULT NULL)
    RETURN VARCHAR2
    ;

Parameters

Table: GET_BLOB_FILE_SRC Parameters describes the parameters available in GET_BLOB_FILE_SRC function.

GET_BLOB_FILE_SRC Parameters

Parameter Description

p_item_name

Name of valid application page ITEM that with type FILE that contains the source type of DB column.

p_v1

Value of primary key column 1.

p_v2

Value of primary key column 2.

p_content_disposition

Specify inline or attachment, all other values ignored


Example

As a PLSQL Function Body:

RETURN '<img src="'||APEX_UTIL.GET_BLOB_FILE_SRC('P2_ATTACHMENT',:P2_EMPNO)||'" />';

As a Region Source of type SQL:

SELECT ID,
       NAME,
       CASE WHEN NVL(dbms_lob.getlength(document),0) = 0
            THEN NULL 
            ELSE CASE WHEN attach_mimetype like 'image%'
                      THEN '<img 
src="'||apex_util.get_blob_file_src('P4_DOCUMENT',id)||'" />' 
                      ELSE '<a 
href="'||apex_util.get_blob_file_src('P4_DOCUMENT',id)||'">Download</a>'
                      end 
        END new_img
   FROM TEST_WITH_BLOB

The previous example illustrates how to display the BLOB within the report, if it can be displayed, and provide a download link, if it cannot be displayed.