Display image blobs directly in UIWebView?
-
20-09-2019 - |
Question
I have a bunch of images stored in my database as blobs that I need to include in a UIWebView. I'd like to do this directly -- without first saving them as temp files. Is there a way to display images in UIWebView with raw data instead of a URL?
Solution
Use RFC 2397, the data URI scheme. Mark Kolich has a nice write-up for it in various contexts. He mostly is discussing CSS, but HTML is the same (and he gives an HTML example).
OTHER TIPS
I assume on the iPhone WebKit still loads URLs through the Cocoa URL loading system. If so, the best approach is for you to subclass NSURLProtocol and create your own custom scheme that loads data from your database. Bear in mind that this will be on a background thread, so watch out for thread safety.