Home
Analytics
Display image saved as Blob from database
Nikhil Mahajan
<p>I have been trying to display and image from database where image is stored as Blob.</p>
<p> </p>
<p>I am using image component of BirtDesigner as Dynamic Image. </p>
<p> </p>
<p>But image is not getting rendered. I am still getting the broken image icon.</p>
<p> </p>
<p>I have attached the result preview of the dataset showing image data as Blob. I a have already tried by changing the datatype to <strong>any</strong> from <strong>Blob</strong> but it didn't work</p>
<p> </p>
<p>Is there anything else I am missing.?</p>
<p> </p>
<p> </p>
<p>Thanks</p>
Find more posts tagged with
Comments
JFreeman
<p>Is the image stored as base 64?</p>
<p> </p>
<p>If so, you can decode the base 64 code in the onCreate of the dynamic image element with some code like this:</p>
<pre class="_prettyXprint _lang-js">
importPackage(Packages.javax.imageio);
importPackage(Packages.java.io);
importPackage(Packages.sun.misc);
decoder = new BASE64Decoder();
decodedBytes = decoder.decodeBuffer(this.getRowData().getColumnValue("CLOBData"));
this.data =decodedBytes;
bais = new ByteArrayInputStream( decodedBytes);
bufimg = ImageIO.read(bais);
this.setHeight(bufimg.getHeight() +"px");
this.setWidth(bufimg.getWidth() +"px");
</pre>
Nikhil Mahajan
<p>Hi,</p>
<p> </p>
<p>Thanks for quick reply.</p>
<p> </p>
<p>I don't think we are storing images as base64 encoded even though I tried your method but it didn't work. However it didn't throw any error. Also I was getting <strong>bais </strong>object as <strong>null </strong>while others weren't.</p>
<p> </p>
<p>Also my database is storing images as <strong>Blob </strong>not <strong>Clob </strong>. Can that be reason my image not getting rendered.?</p>
JFreeman
<p>If it is not stored as base64 then the decoder part is going to be unnecessary and may cause it to not work properly. You will still need to convert the image being read in into a byte array for the dynamic image element.</p>
<p> </p>
<p>Take a look a this article: <a data-ipb='nomediaparse' href='
https://wiki.eclipse.org/index.php/Image_By_Building_byte_array_in_Expression_(BIRT)'>https://wiki.eclipse.org/index.php/Image_By_Building_byte_array_in_Expression_(BIRT)</a></p>
;
micajblock
<p>if the blob is truly an image that it should just work. See attached example using Classic Models.</p>