I would like to use temp.jpg
\" />
in my UIWebView\'s HTML.
How can I refer to a local file named
I was searching a lot for a solution and found the following which
in my case working fine, I have a local HTML string and a local image
I convert the image into base 64
you may use this website to convert image to base64 encoding
Converter
and rewrite the HTML string to have the base64 image in the image tag like the following
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAABIAAAAAQAAAEgAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAABmgAwAEAAAAAQAAABkAAAAA/+0AOFBob3Rvc2hvcCAzLjAAOEJJTQQEAAAAAAAAOEJJTQQlAAAAAAAQ1B2M2Y8AsgTpgAmY7PhCfv/AABEIABkAGQMBEQACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2wBDAAkGBxISEhISEhAQFRUXFRUVEhIQDxAQEBUVFRIWFxUVExUYHSggGBolGxUVITEhJSorLi4uFx8zODMtNygtLiv/2wBDAQoKCg4NDhcQEBctHR0dLS0tLS0rLS0rLS0tLTctLS0tLS4tLS0tLS0tLS0uKy0tLS0tLS0vLSstLS0tLS0rLS3/3QAEAAT/2gAMAwEAAhEDEQA/APTbvxzYRSPE85DoxR18qU4YYyMgc9R0rN1YJ2bO2ll2IqxUoRun5ohPxBsO0sh/3bec/wDstQ8TT7/gdCyXGP7K/wDAo/5iR+PrRnjjQTku6ICYSiguwUElscc0LERbsipZLiYxlKVkkm977a9Dq63PIP/Q6bWbLSftc/nzxLNvLOjXZjJyqnlQeDjHHoRWUqMJO7O+jmWIoxUYSVl5JlOW50RHQLNYsn/LQteM5Xn0zWboJSVo3XU0eb4t/wDLy3okizaeJ9CjlRYRCzl0VWitmcBmkVVzIRgckd62jShHZHPUzDE1FadWTXa56dVnIf/R6/xH8J7W9upbqS4ulaRlYpE0SoCsapwSpPRB3oASD4Pacv3nvG+t0y/+ggUAalh8NNMiIYWxYgggzTTS8g5BwzYzkCgDrsUAf//S9xoAKACgAoA//9k=" alt="Red dot" >
for Testing the result tye the following Online HTML editor
W3School
hope it will help for others or maybe get a better solution, best of luck
This will create a URL object that contains the location of your file on disk. You can then use this to output a valid file://
URL string that can be used within img
tags.
NSURL* fileURL = [[NSBundle mainBundle] URLForResource:@"temp" withExtension:@"jpg"];
NSLog(@"<img src=\"%@\" />", fileURL.absoluteString);
NSURL *url=[[NSBundle mainBundle] bundleURL];
[webView loadHTMLString:string baseURL:url];
This let's the root be the app's main bundle.
I have no idea where my root is...
UIWebView
looks up files relative to the HTML file you loaded in it. So perhaps it will be your app bundle.