Oracle APEX:如何显示局域网共享文件夹中的图片
Got it, let's break down how to show those \\SCANS\... images in your Oracle APEX app. I’ve worked through this exact scenario a few times, so here are the two most practical approaches depending on your environment:
1. Web Server Mapping (Recommended for Performance)
Browsers block direct access to \\ network paths for security reasons, so the cleanest fix is to map your shared folder to a web-accessible URL using your APEX web server (like Oracle HTTP Server or Tomcat).
Steps to Configure:
Map the Shared Folder as a Virtual Path:
If you’re using Oracle HTTP Server (OHS), edit your server’s config file (e.g.,httpd.confor a custom.conffile in theconf.ddirectory) to add an alias pointing to your network share:Alias /scans/ "//SCANS/"Then add directory permissions to allow access:
<Directory "//SCANS/"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>Pro Tip: Make sure your web server’s service account has read permissions to the
\\SCANSshare—this is a common gotcha that trips people up!Use the Virtual URL in APEX:
Now you can reference images directly using the virtual path. For example:- In an Interactive Report, set the image column’s source to
'/scans/' || your_image_path_column - In a Form’s Image component, use a dynamic URL like
'/scans/01/01-0001.GIF'(or bind to a page item like'/scans/' || :P1_IMAGE_PATH)
- In an Interactive Report, set the image column’s source to
2. PL/SQL Dynamic Content (If Web Server Config Isn’t Possible)
If you can’t modify the web server (e.g., no admin access), you can use PL/SQL to read the image from the network share and stream it directly to the browser.
Prerequisites:
- Your database server must have access to the
\\SCANSshare. On Windows, map it to a local drive (e.g.,Z:\); on Linux, mount it usingcifs-utils. - Create a database directory object pointing to the mapped/mounted path:
CREATE OR REPLACE DIRECTORY SCANS_DIR AS 'Z:\'; - Grant read access to APEX’s runtime user (typically
APEX_PUBLIC_USER):GRANT READ ON DIRECTORY SCANS_DIR TO APEX_PUBLIC_USER;
Implement in APEX:
- Create a new blank page (e.g., page 100) dedicated to serving images.
- Add a Dynamic Content region to the page, with this PL/SQL code:
DECLARE l_file BFILE; l_blob BLOB; BEGIN -- :P100_IMAGE_PATH is a page item that holds the relative path (e.g., '01/01-0001.GIF') l_file := BFILENAME('SCANS_DIR', :P100_IMAGE_PATH); DBMS_LOB.OPEN(l_file, DBMS_LOB.LOB_READONLY); DBMS_LOB.CREATETEMPORARY(l_blob, TRUE); DBMS_LOB.LOADFROMFILE(l_blob, l_file, DBMS_LOB.GETLENGTH(l_file)); DBMS_LOB.CLOSE(l_file); -- Set HTTP headers for GIF images OWA_UTIL.MIME_HEADER('image/gif', FALSE); HTP.P('Content-Length: ' || DBMS_LOB.GETLENGTH(l_blob)); OWA_UTIL.HTTP_HEADER_CLOSE; -- Stream the image to the browser WPG_DOCLOAD.Download_FILE(l_blob); DBMS_LOB.FREETEMPORARY(l_blob); END; - On your main page, use this URL as the image source:
Replacef?p=&APP_ID.:100:&SESSION.::NO::P100_IMAGE_PATH:01/01-0001.GIF100with your image-serving page number, and bindP100_IMAGE_PATHto your actual image path value.
Key Notes:
- Always test permissions first—if the web server or database account can’t access the share, nothing will load.
- For large image libraries, the web server mapping method is faster and more scalable than streaming via PL/SQL.
内容的提问来源于stack exchange,提问作者shahidyasin

