Creating dynamic images from BLOBs in database

Options
MoonDawg
edited February 11, 2022 in Analytics #1
<p>Hello everyone! I'm brand new to BIRT and was hoping someone could help me with a problem I'm having.</p>
<p> </p>
<p>I'm trying to display a dynamic image in my report, but I'm hitting some issues. I'm querying the image data from our database, converting the Byte array to Base 64, and writing that Base 64 into an XML file. So, our XML data source is using Base 64 as the image data. Below is an excerpt of what it looks like in the XML file.</p>
<p> </p>
<p><strong><cImage>/9j/4AAQSkZJRgABAAEAYABgAAD/2wCEAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQ...</cImage></strong></p>
<p> </p>
<p>I tell BIRT that "cImage" is the column that I want to use and that it is a BLOB. However, whenever I run my report, I get the following error:</p>
<p> </p>
<p><strong>"</strong><b><span>org.eclipse.birt.report.engine.api.EngineException: A BIRT exception occurred. See next exception for more information. Can not convert the value of /9j/4AAQSkZJRgABAAEAYABgAAD/2wCEAAMCAgIC... to Binary type."</span></b></p>
<p> </p>
<p>Should I be using something other than Base 64?</p>
<p> </p>
<p>I feel as if I'm missing a very simple step and could really use some guidance since I'm a newbie. Any help would be greatly appreciated. Thank you!! :)</p>

Comments

  • Clement Wong
    Options
    <p><em>I'm trying to display a dynamic image in my report, but I'm hitting some issues. I'm querying the image data from our database, converting the Byte array to Base 64, and writing that Base 64 into an XML file</em></p>
    <p> </p>
    <p>Why do you need to do all these conversions?  It would much easiier if you read the Byte array from the database in the report design, and display the image using the Image Report Item.</p>
    <p> </p>
    <p>If you still need to do these conversions, Base64 is correct.  But the Image Report Item is expecting a BLOB data type.</p>
    <p> </p>
    <p>You have two options...</p>
    <p> </p>
    <p>1. Use a Text Report Item and display the image with your Base64 string.</p>
    <pre class="_prettyXprint">
    <img src='data:image/png;base64,<VALUE-OF>row["cImage"]</VALUE-OF>'></pre>
    <p>2. Use a Image Report Item with the image selected as "Dynamic Image".  It's expecting a BLOB here.  You will need to convert the Base64 String into a BLOB in the binding.</p>
    Warning No formatter is installed for the format ipb
  • Hi,

    Use the following code on image render.

    Example:-

    importPackage(Packages.java.io);
    importPackage(Packages.java.lang);
    importPackage(Packages.java.net);
    importPackage(Packages.javax.imageio);
    var myfile = new Packages.java.io.File(row["GDS_DOC_CONTENT"]);
    var img = ImageIO.read(myfile);
    bas = new ByteArrayOutputStream();
    ImageIO.write(img, "jpeg", bas);
    this.data = bas.toByteArray();