0

I'm trying to display an image from a collection.

The current methods (apex_util.get_blob_file_src / dbms_lob.getlength) don't seem to work, since this is a collection and not a Table. I'm able to create a download link of the image/file but not display it. Any ideas on how to display images from collection in a report?

The report query looks like that (without the section to display image)

select
    seq_id as "Seq id",

    n001 as "Id",

    '<a href="' || apex_page.get_url(p_page => 3003, 
                                 p_clear_cache => 3003,
                                 p_items => 'P3003_SEQ', 
                                 p_values => seq_id)
        ||'">' || c002 || '</a>'
    as "Download document"

from APEX_COLLECTIONS
where collection_name = 'COLLECTION_DOCS';

Thanks

Progman
  • 16,827
  • 6
  • 33
  • 48
Izik
  • 746
  • 1
  • 9
  • 25

1 Answers1

1

You could transform the image to base64 with a function and use the output in the img src attribute.

Here is some code to transform the blob to a base64 encoded clob.

Afterwards you can use that clob in an HTML img tag:

<img alt="" src="data:'|| img_mime_type || ';base64, '|| base64_img || '">

You need to set the mime type based on your image format. E. g. for png use "image/png".

  • Thanks! your solution is working, but unfortunately only for small images. I tried making some changes in the code mentioned in your link (I used the function since I cannot use procedure). My best-case scenario is when I use this code: return UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(DBMS_LOB.substr(image_blob, 22500, 1))) --> where image_blob is the BLOB column. Using for loop, as mentioned in the link and other places, cause "ORA-06502: PL/SQL: numeric or value error: character string buffer too small". Do you know how can I solve it? – Izik Nov 22 '22 at 19:38
  • BTW, if relevant, the VARCHAR2 is max 4000 since the DB definition is not set to "Extended" – Izik Nov 22 '22 at 19:39