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

Discussion in 'iOS Questions' started by aeric, Oct 5, 2018.

  1. aeric

    aeric Active Member Licensed 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:
    Code:
    myimage.jpg written to /var/mobile/Containers/Data/Application/5E43A1B2-2468-123B-A456-B1BB22F330BC/Documents/
    I build my html like:
    Code:
    strHtml = strHtml & $"<p><img src="file://"$ & File.Combine(File.DirDocuments, "myimage.jpg") & $"" width="100%"></p>"$
    Is there a workaround?
     
  2. aeric

    aeric Active Member Licensed User

    I change my HTML to the following so the webview just load the image from the server:
    strHtml = strHtml & $"<p><img src="https://mydomain.com/images/"$ & strfilename & $"" width="100%"></p>"$

    Just wondering whether webview able to load the image from device storage such as
    File.DirDocuments?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    You are not using the string literal correctly.

    Code:
    strHtml = strHtml & $"<p><img src="file://${File.Combine(File.DirDocuments, "myimage.jpg")}" width="100%"></p>"$
    You can load images from File.DirDocuments.
    Example:
    Code:
    File.Copy(File.DirAssets, "smiley.png"File.DirDocuments, "1.png")
    WebView1.LoadHtml(
    $"<img src="file://${File.Combine(File.DirDocuments, "1.png")}"/>"$)
     
  4. aeric

    aeric Active Member Licensed User

    Thanks Erel. Will try the code later.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice