Samstag, 22. April 2017

Caching Blob Images in Browser

I have a application where More as 50 images are display in one of my Page. All Images are blob. The problem is that the Images are not caching. They reload each Time the Page reload. That is not efficient for the Users.  it could very User friendly to have the Images Caching in Client Side.

 What was wrong?(Don't display Blob Images with this Way. It is BAD)

 1-The SQL Code

select dbms_lob.getlength( ((select DATEIINHALT from TAB_DATEIEN where TAB_DATEIEN.SAP_PRODUITS_ID=SA_PRODUITS.SAP_PRODUITS_ID and position=1)))   card_title from MY_TABLE

Declarative BLOB masks generate URLs that download image files using the apex_util.get_blob_file API method. This does not set cache control headers. If you want to control browser caching using HTTP response headers, use a custom On-Demand Process to download the BLOB content.

2-Result



How to caching Blob Images in Browsers

1- Create a Application Item. For Example in my Case FILE_ID

2- Create a Application Process mit the Name GETIMAGE and add as PL/SQL CODE this Code

BEGIN apex_debug.message (
    'file_id = %s'
    ,: file_id
)
; FOR c1 IN (
    SELECT
            *
        FROM
            TAB_DATEIEN-- Table for my Images
        WHERE
            TAB_DATEIEN.SAP_PRODUITS_ID = :FILE_ID--Application Item
            AND POSITION = 1
) LOOP --
 apex_debug.message (
    'Downloading file: %s'
    ,c1.DATEINAME
)
; sys.htp.init
; sys.owa_util.mime_header (
    c1.MIMETYPE
    ,FALSE
)
; sys.htp.p (
    'Content-length: ' || sys.dbms_lob.getlength (c1.DATEIINHALT)
)
; sys.htp.p (
    'Content-Disposition: attachment; filename="' || c1.DATEINAME || '"'
)
; sys.htp.p ('Cache-Control: max-age=3600')
; -- tell the browser to cache for one hour, adjust as necessary
 sys.owa_util.http_header_close
; sys.wpg_docload.download_file (c1.DATEIINHALT)
; apex_application.stop_apex_engine
;
END LOOP
;
END
;


3- Call your Image in your Report like so

select  '<img src='||'f?p='||:APP_ID||':14:'||:APP_SESSION||':APPLICATION_PROCESS=GETIMAGE:'||:debug||'::FILE_ID:'||SA_PRODUITS.SAP_PRODUITS_ID||'>' card_title from my_table

4- Result



Keine Kommentare:

Kommentar veröffentlichen