iOS Question [Solved] Load image file from File.DirDocuments in Webview

aeric

Expert
Licensed User
Longtime User
Hi guys,

I download an image from my server and store in File.DirDocuments. I want to display the image in webview using html but the image doesn't show.

I log the destination folder and show:
B4X:
myimage.jpg written to /var/mobile/Containers/Data/Application/5E43A1B2-2468-123B-A456-B1BB22F330BC/Documents/

I build my html like:
B4X:
strHtml = strHtml & $"<p><img src="file://"$ & File.Combine(File.DirDocuments, "myimage.jpg") & $"" width="100%"></p>"$

Is there a workaround?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are not using the string literal correctly.

B4X:
strHtml = strHtml & $"<p><img src="file://${File.Combine(File.DirDocuments, "myimage.jpg")}" width="100%"></p>"$

You can load images from File.DirDocuments.
Example:
B4X:
File.Copy(File.DirAssets, "smiley.png", File.DirDocuments, "1.png")
WebView1.LoadHtml($"<img src="file://${File.Combine(File.DirDocuments, "1.png")}"/>"$)
 
Upvote 0
Top