Search code examples
imagekitura

How to turn base64 encoded data back into an image without using UIImage in Swift?


I'm writing a Swift Server that accepts and saves a base64 String which has encoded a UIImage via UIImageJPEGRepresentation (so I can compress it). This string is then sent as JSON, where it is saved to a Swift Cloudant database. However, the server doesn't have access to UIKit, so I can't refer to a UIImage in it's code to decode it back into a picture. Is there a way to turn the String back into a picture without using UIImage?

Pure Swift would be the best option, but I don't know if it's actually possible. My server is a Kitura one, hosted on IBM Bluemix. Thank you!

(The goal is to show the picture on a webpage.)


Solution

  • I don't know if it can help but as you need to show this image on a website I, in an application where I need to show a webview with a image,used this (in the .html file containing my webpage)

    <img src="data:image/png;base64,#IMAGE_STRING#">

    and when I run the application the "#IMAGE_STRING#" is replaced by the base64 string containing the image , the result is : my image is showing perfectly in the webpage