Base64 image

3
I want to show images in mendix from a Base64 code. The image code is an attribute of my entity. Can I use the imageviewer to show this image from a Base64 code? Edit: I'm going to create a new image from the Base64 code and save this as a image in an object. After that I'm going to set a asssocation to the image. Thanks for the answers Rob and Achiel.
asked
4 answers
3

If the base64 encoded image string happens to be in an XML document that you'll have to map anyway, you can simply map it on the Contents attribute of a System.Image object in your XML-to-domain mapping. After this, you can use that object as you normally would, i.e. show it using the Mendix image viewer.

answered
3

Not sure, but this might be worth a try: you could use one of the solutions in this stackoverflow thread and send the inputstream to a new image.

answered
2

Not directly, you have to save it to an imagedocument first, then you can display it as you would normally. See Robert's answer for info on how to decode base64 to an inputstream.

answered
0

Note that most browser are capable of directly showing base64 data as image. So you could generate an img tag with the base64 data and display it using the richt text viewer.

For example:

<img src="data:image/png;base64, DATAHERE" alt="unable to display"/>

Of course your mime type needs to be correct.

answered