Creating dynamic images from BLOBs in database

Hello everyone! I'm brand new to BIRT and was hoping someone could help me with a problem I'm having.


 


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.


 


<cImage>/9j/4AAQSkZJRgABAAEAYABgAAD/2wCEAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQ...</cImage>


 


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:


 


"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."


 


Should I be using something other than Base 64?


 


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!! :)


Comments

  • 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


     


    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.


     


    If you still need to do these conversions, Base64 is correct.  But the Image Report Item is expecting a BLOB data type.


     


    You have two options...


     


    1. Use a Text Report Item and display the image with your Base64 string.



    <img src='data:image/png;base64,<VALUE-OF>row["cImage"]</VALUE-OF>'>

    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.

    Clement Wong
    Principal Analytics Architect

    OpenText Corporation
    http://www.actuate.com | http://www.opentext.com

  • 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();

Sign In or Register to comment.