Issue where images from local paths cannot be retrieved in Cordova Webview starting from iOS 26.4

Hello.

I am using Cordova Webview to select a photo from the album, save it locally, and then pass the saved path to the web for display.

It displayed correctly up to OS 26.3.x, but starting from OS 26.4.x, I am unable to retrieve images from local paths. Part displayed in Cordova Webview

<img src="file:///var/mobile/Containers/Data/Application/.../tmp/cdv_photo_006.jpg" width="auto" height="auto" alt="" draggable="false" id="box" class="sc-bczRLJ sc-gsnTZi eVuMcq blHpFC" style="object-fit: contain; width: 100%; max-height: 368px;">

I have also confirmed the existence of the corresponding file in the src path.

Are there any known bugs or solutions?

Thank you.

Answered by DTS Engineer in 885149022

Thanks for your post and your insight on this one.

Based on the code snippet and the behavior you are describing in WKWebView, I’m sure the issue is as you describe caused by appending a query string (? + timestamp) to a file:// URI.

Xcode does not handle HTML and modifies the WKWebView. Is after the tools and developers to set the HTML to display on the WKWebView.

Unlike http:// or https:// URLs, file:// URIs do not natively support query parameters, appending ?1776643364151 causes the system to look for a file literally named profile_image.jpg?1776643364151 on the disk. Because that file doesn't exist, WKWebView returns a broken image?

I believe is important to highlight the 3rd party tool you are using is the one that generates the custom HTML?

When loading your local HTML file, and does not ensure the allowingReadAccessTo parameter points to a directory high enough in the file tree to encompass both your HTML files and your saved images.

I suggest you first check with the third-party tool, as they’re the ones creating the output. Of course, you’ll still need to decide what you want to inject into the WKWebView.

Albert
  Worldwide Developer Relations.

Thank you for the question. I would recommend check with the support resources provided by the 3rd party to get assistance with their software.

Unless another developer in the forums has experience with the third-party and can provide assistance. However I didn't see any reply in one day and I'm sure the 3rd party component may have information about this issue.

Good luck!

Albert
  Worldwide Developer Relations.

Hi Albert It does not appear to be a Cordova issue.

Even in WkWebview, when I configured the system to display the path in the img field after saving an image from the Album to App Local, it is being displayed as "?" images starting from OS version 26.4.

  • It displayed correctly in 26.3.x.
  1. html code

<body> <div class="proFileImg"> <img id="profile" src="images/No_Image.jpg" style="width:100px; height:100px;" /> </div> <input type="button" value="Browse image files" onclick="openNativePicker()" /> </body> <script type="text/javascript"> function openNativePicker() { if (window.webkit && window.webkit.messageHandlers.openPicker) { window.webkit.messageHandlers.openPicker.postMessage(""); } } function setNativeProfileImage(fileUrl) { if(fileUrl) { // Insert the file:// address directly into src $("#profile").attr("src", fileUrl + "?" + new Date().getTime()); } } </script>

  1. Inspector debugging

<img id="profile" src="file:///var/mobile/Containers/Data/Application/D8B76F49-AB43-47B1-A3CE-B6981C493EC7/Documents/profile_image.jpg?1776643364151" style="width:100px; height:100px;">

-> The profile_image.jpg file is saved in the Documents local path.

Accepted Answer

Thanks for your post and your insight on this one.

Based on the code snippet and the behavior you are describing in WKWebView, I’m sure the issue is as you describe caused by appending a query string (? + timestamp) to a file:// URI.

Xcode does not handle HTML and modifies the WKWebView. Is after the tools and developers to set the HTML to display on the WKWebView.

Unlike http:// or https:// URLs, file:// URIs do not natively support query parameters, appending ?1776643364151 causes the system to look for a file literally named profile_image.jpg?1776643364151 on the disk. Because that file doesn't exist, WKWebView returns a broken image?

I believe is important to highlight the 3rd party tool you are using is the one that generates the custom HTML?

When loading your local HTML file, and does not ensure the allowingReadAccessTo parameter points to a directory high enough in the file tree to encompass both your HTML files and your saved images.

I suggest you first check with the third-party tool, as they’re the ones creating the output. Of course, you’ll still need to decide what you want to inject into the WKWebView.

Albert
  Worldwide Developer Relations.

Issue where images from local paths cannot be retrieved in Cordova Webview starting from iOS 26.4
 
 
Q