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.

src:
        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
 

MitchBu

Well-Known Member
Licensed User
Longtime User
I have done the same I do in the help files I use. Now it works:

B4X:
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

Semen Matusovskiy

Well-Known Member
Licensed User
Imagine that you want to show 1.jpg, which you included using File Manager tab in IDE.
B4X:
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

MitchBu

Well-Known Member
Licensed User
Longtime User
Imagine that you want to show 1.jpg, which you included using File Manager tab in IDE.
B4X:
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

MitchBu

Well-Known Member
Licensed User
Longtime User
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

Semen Matusovskiy

Well-Known Member
Licensed User
The code you posted works only with File.DirAssets and File.DirTemp
I wrote a little sample. Works fine in simulator.
But does not show a picture on iPhone for DirLibrary and DirDocuments. Strange.
 

Attachments

  • s56.zip
    2.5 KB · Views: 153
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
What does this statement suppose to mean?

Have you been there :
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
You mean this works for you?
B4X:
WV.LoadUrl("file://" & File.Combine(Dir, FileName))

But this not works for you?
B4X:
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

aeric

Expert
Licensed User
Longtime User
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

MitchBu

Well-Known Member
Licensed User
Longtime User
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
Top