-2

I have studied similar questions but couldnot find solution.

I am using WkWebView. It renders a html from library directory so i did loadfileurl.

It has option of displaying an image, we select the image from gallery/take camera , then from image data wecreate a file in library directory and sendthe path to web . I tried both path var/... and also appended file:// both cases image is not displaying. Please help. Any suggestions appreciated.

Gypsa
  • 11,230
  • 6
  • 44
  • 82

1 Answers1

0

An alternative would be to encode the images as base64 strings and insert them into the HTML before rendering. You could either save the images as images or the base64 string, depending on whether you need to use them in another context.

// Get the base64 representation of the image
let image = UIImage(named: icon) // This could also be loaded from the file system
let data = image!.pngData()
let b64String = String(data: data!.base64EncodedData(), encoding: String.Encoding.utf8)!
let finalString = "data:image/png;base64," + b64String

// Insert into HTML string before rendering in webview
let myHTML = baseHTML.replacingOccurrences(of: "#PLACEHOLDER#", with: finalString)

You will need to have #PLACEHOLDER# in your HTML file at the point where you would have the path to the image.

Chris
  • 4,009
  • 3
  • 21
  • 52