Loading PDF from base64 results in empty file url

94 Views Asked by At

Based on this answer I'm trying to open a PDF in the web view of my app.

private func handlePdf(url: String) {
   // get the base64 encoded part of the url
   let base64String: String = String(url.split(separator: ",")[1])
   let decodeData = Data(base64Encoded: base64String, options: .ignoreUnknownCharacters)
   webView?.load(decodeData!, mimeType: "application/pdf", characterEncodingName: "UTF-8", baseURL: URL(fileURLWithPath: ""))
}

The incoming dataurl looks like this: data:application/pdf;name=test.pdf;base64,JVBERi0xLjMNCiXi48/TDQolUlNUWFBERjMgUGFyYW1ldGVyczogRF ... JSVFT0YK

However, the load method of webView is called with file:/// and absolutely nothing happens.

If I follow the advice given here, then safari would simply open with the passed URL (https://www.google.com) in this case.

Any tips and hints are greatly appreciated.

0

There are 0 best solutions below