JSON datasource with image as base64 string
Hello
I am trying to show a picture in a Report.
The connection type is JSON, and the picture is a base64 encoded string.
But the picture is not displayed 😕
Thanks for your help!
Christian
This discussion has been closed.
Comments
Hi you might already found a solution for yourself, but I want to add mine just in case. You can actually Right click on the JSON table then click on new Calculated Column and on the property panel of the new calculated column, set DataType to Byte[], expand the Expression popup editor and type in
Convert.FromBase64String([JSON.item.Image]) whereas JSON.item.Image is your Base64 string column
Hello!
To resolve this issue, you can decode the Base64 string into a byte[] in the Picture1_BeforePrint event using SetImageData(...):
private void Picture1_BeforePrint(object sender, EventArgs e) { var pic = (PictureObject)sender; string b64 = Convert.ToString(Report.GetColumnValue(“JSON.item.ImgB64”)); if (!string.IsNullOrEmpty(b64)) { int comma = b64.IndexOf(‘,’); if (comma >= 0) b64 = b64.Substring(comma + 1); // if there is a prefix like data:image/...;base64, pic.SetImageData(Convert.FromBase64String(b64)); } }