iOS Question Pictures in WebView HTML

MitchBu

Well-Known Member
Licensed User
Longtime User
I am trying to display a picture file in the B4i WebView, but it does not work.

Here is how I get the code for an img tag src. Before calling that, I make sure the file exists.

Code: Copy
        Dim src As String = QUOTE & xui.FileUri(AppData, filenameLetterPicture) & QUOTE

I get a full path to a file:

src: "file:///var/mobile/Containers/Data/Application/EF6DB2F1-7AE0-4441-945A-26D01E0D276E/Library/com.bujardet.data/test2_1618643146657_letter_logo.jpg"

Problem is, nothing appears.

What should I do ?

TIA
 
I have done the same I do in the help files I use. Now it works:

B4X: Copy
Dim src As String
        src = QUOTE & "data:image/jpeg;base64,"
        Dim su As StringUtils
        src = src & su.EncodeBase64(File.ReadBytes(AppData,filenameLetterPicture)) & QUOTE
 
Upvote 0
Upvote 0
Imagine that you want to show 1.jpg, which you included using File Manager tab in IDE.
Code: Copy
WebView1.LoadHtml ("<img width=100% src=" & QUOTE & xui.FileUri (File.DirAssets, "1.jpg") & QUOTE & ">")

Interesting, why this code works.
In topics dated 5-6 years ago I saw a recommendation to copy pictures from assets to physical folders . Probably, something was changed in IOS.
 
Last edited:
Upvote 0
Imagine that you want to show 1.jpg, which you included using File Manager tab in IDE.
Code: Copy
WebView1.LoadHtml ("<img width=100% src=" & QUOTE & xui.FileUri (File.DirAssets, "1.jpg") & QUOTE & ">")

Interesting, why this code works.
In topics dated 5-6 years ago I saw a recommendation to copy pictures from assets to physical folders . Probably, something was changed in IOS.

Strange. It does work with DirAssets indeed.

But as soon as I use another folder, no luck :(

I wonder if that is not a problem of permissions.
 
Last edited:
Upvote 0
OK. After much trial and error, here is what I found out:

The code you posted works only with File.DirAssets and File.DirTemp.

So now what I do is, to copy pictures to File.DirTemp before displaying them in WebView HTML.
 
Upvote 0
What does this statement suppose to mean?

Have you been there :
 
Upvote 0
You mean this works for you?
B4X: Copy
WV.LoadUrl("file://" & File.Combine(Dir, FileName))

But this not works for you?
B4X: Copy
WV.LoadHtml($"<img src="${xui.FileUri(Dir, FileName)}"/>"$)
 
Upvote 0
You mean this works for you?
B4X: Copy
WV.LoadUrl("file://" & File.Combine(Dir, FileName))

But this not works for you?
B4X: Copy
WV.LoadHtml($"<img src="${xui.FileUri(Dir, FileName)}"/>"$)

If you care to read the whole thread, what happens is that if the picture file is pointed at as an src, it displays only if it is in file.DirAssets, or File.DirTemp.
 
Upvote 0
Yes, it works for File.DirAssets out of the box. Isn’t this what you wanted? Why you want to use other locations?
 
Upvote 0
I see. As far as I know, only DirDocuments is writable. I remember ImageView can read from this location. If you want to use WebView then I think the only option is to copy the image to DirTemp.
 
Upvote 0
Indeed, the only places where images can be placed for WebView are DirAsset and DirTemp.

So what I do after the user has selected a picture, is to copy it to my subfolder in Library for backup, and to DirTemp to display.

When the app launches, it copies if necessary all pictures in the Library subfolder to DirTemp.
 
Last edited:
Upvote 0
Back
Top