I have a simple image populated from a data uri that loads fine in MobileSafari, but when I load the same webpage in a UIWebView, it shows as a broken image:
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQSEhQUEhQUFBUUFBQUFBcVGBUUFhUVFRUWFhQUFBQYHSggGBolHBQUITEhJSkrLi4uFx8zODMsNygtLisBCgoKDg0OGhAQGiwkHx8sLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCw3NyssLC4rLP/AABEIAMEBBQMBIgACEQEDEQH/xAAcAAABBQEBAQAAAAAAAAAAAAABAAIDBAUGBwj/xAA8EAABBAAEBAIJAwIFBAMAAAABAAIDEQQSITEFQVFhBnETIjJCgZGhsfAUwdFS4QdDkqLxI2JyghUzU//EABkBAAMBAQEAAAAAAAAAAAAAAAABAwIEBf/EACURAAICAgEFAQACAwAAAAAAAAABAhEDEiEEEyIxQVEUYUJSgf/aAAwDAQACEQMRAD8A8+GNjL2Bjgxxd7R2ZfMlU8bi7e7M8yAHKH/1Ac1mQtU7xosKIGhh+KujLTGAAL3AN3vZ8k1mLcHaEjNdgbarNw+bNTbPbddEOBnLE8ihKAR/BUpaR9jSZ2nh55DWAXQAsHuu0bNQHkuM4Y4R6Hkt93EbA8l4WRpNnXFcG/BMCpCQucgxJu7WgMTaj3Ua1NAy0mOnKpiRSB6w8iY6JjKVGxhJ9ZD0iLSd6WHJMdEuJlyt06qq2RXIMNYBcL3KuR4ZoF0LpKcZSkvw0mkZAZ65Wngt1z+NxHo5geWx8l0WAF6jovS6aV8fhjLGuS8iEEV2nMJJFMlkDRZ0ATbD2OQK5bifiRzLy0ADptqt7hONE8TJB7w17EGipwyqTpG5Y2lZbKBTkCqGAIJyCABSCKCAGlBOTUANQKcgmAxJFJAHy7hwpZEOGQuke2NgzPe5rGNG5c4hrQL6khXncHnLp2CJ5dh2udOK/wDqaw04u7aL0CJqeAMIHTucdmNPzdour4k9rQ1oGjTp2Vf/AA94E84Y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WZKxp0REdU15/Apf0/c/RROiIWHA1sUZoTatYXBB2+w37qr+o9cjoPJTniTWbkWSCB2CxDGnLk05OjTa1jNgB10UL8QLs7LFl48A8NJFSWb6Ea1fkqPEsU+wQaaDbvIAlXcVXCJcmzjn3oNCfiFnStACrYHi4miEmazs4cw6tRSilx4Oi580Ui0JD2ij2P0VxlKlGCNeqtRHRRxr9NtlPiOGNWz5LDkkcuneVnYuEHX8pb31LY8tezHbMdirMOJIV2HhsUmp3+P7KceG2e6948nA/cLoULVmZdSkDDY1aUU4KzDwB7dpL8wL+YP7IR5mGnBPmPs1HJGa4NlRuYCoopFMHLQmVJsJzb8lWulpkqKaEO8+qlKJKUF8KWdOD0JYiO6ZazbRKiUOSVdxST3Edcimgogq5McCjabaVoAeCnWmAo2mA9Gky04FABSCARBQAbStIFEoAr4iO9/msPiWFJ94Gum/yXRFVcRgw7t5ISQcnm/iDAuOhcdDttYtVosc5jHQ5zmNVY0APTsux8Q+FnYhha2Ux3zAB/AuUxXg/GsDSx0MpYMoJzRktB0u7BPe1SK/sL/o3fDXDvQNaXn1nGxy18lrcegbJE17azZqHKyeS46HEY6N4diIJC1nshjWvF+bCdFscM4i/EEsMTw3R3rAtIPa+inkiaiwQ8QsAGxXI8uqtYfFCt1uR4cAafsnegUO2a3Ml0ml/wA0qE5OYaWD0XRvBHJQ20e5R8ku3yPYgw8IA2pWA2kc4UT5gFZcGVFssF2iqYht9004hN/Up+y0YUBjKUlpvpQUcyVFBzXJyjRzIEPIUMkAKkLkC9ZaBqyqYElO6RJZ1QtUbYRCKSqcgUkkkAFOCCSYDkgkkgBwRKKSAAikkgAlNRSQCAo5EkkmMgChd7f51RST+GfpKgUklhGwtUWI3RSTkNFWfZZkvNJJZKw9kblG1JJBZkrFI1FJaQh7USkkgQCgUkkmMickkkkB/9k=">
I have no idea why. Is there some magic configuration of the UIWebView that I've forgotten?
Edit:
In Safari Web Inspector pointing to the UIWebView, I notice that it is interpreting the data uri as application/json
, whereas if I load the file from the same server in MobileSafari, web inspector correctly recognizes it as image/jpeg
.
I ended up working around the issue by embedding the file in my app bundle, and setting the base URL of my webview to the parent of that file:
I copied your image src data uri and created a simple html file and loaded it in uiwebview.It was working fine and I did not see any problem in loading your jpeg image file using a local html file. Please see the html file created below.
Loaded this sample.html in uiwebview in viewdidload using below code.
Don't forget to add your html file to your xcode project. Please check if this works for you.