Cannot bind image to ColdFusion report input parameter

717 views Asked by At

I am working with ColdFusion Report Builder for CF9 and trying to pass a chart into a report as a PNG image. Here's my CFML code:

<cfchart format="png" name="chartImage">
    <cfchartseries type="bar" query="chart" itemcolumn="title" valuecolumn="level">
</cfchart>
<cfreport format="pdf" template="report.cfr" name="grid">
    <cfreportparam name="reportTitle" value="#reportType.title#">
    <cfreportparam name="chartImage" value="#chartImage#">
</cfreport>

In CF Report Builder I have defined an Input Parameter called chartImage and set it to a type of BLOB (also tried type Image), following these instructions exactly.

I am getting this error and haven't been able to overcome it:

Report data binding error Incompatible [B value assigned to parameter chartImage in the ColdFusionReport dataset..

I've also changed the parameter type to String, passed in a base-64 string and then converted it to binary within the report, but that throws an error with an unhelpful message of [B.

How can I get this image to bind correctly as an input parameter?

2

There are 2 answers

1
imthepitts On BEST ANSWER

I suppose the lack of interest in this question speaks to the popularity of CF Report Builder. While I have not been able to overcome the binding error, I did find a reasonable workaround.

Instead of directly binding the image as a binary value, I am writing the chart image to the temp directory and then passing that path into the report as a string parameter. The report then can find the image from the file system and attach it to the report without any trouble. Once the report has been run, I delete the chart from the file system to ensure everything stays nice and tidy.

Here's the updated code with this solution:

<cfchart format="png" name="chartImage">
    <cfchartseries type="bar" query="chart" itemcolumn="title" valuecolumn="level">
</cfchart>

<cfset chartImageFile = getTempDirectory() & '\' & createUUID()>
<cfset fileWrite(chartImageFile, chartImage)>

<cfreport format="pdf" template="report.cfr" name="grid">
    <cfreportparam name="reportTitle" value="#reportType.title#">
    <cfreportparam name="chartImage" value="#chartImageFile#">
</cfreport>

<cfset fileDelete(chartImageFile)>

It's not very elegant, but nothing about CF Report Builder has been particularly elegant.

0
Josh On

I know this is quite old, and CF Report Builder is being deprecated. However, I recently had to come up with a solution. CF Report Builder's image parameter does not like byte arrays, Coldfusion's own image class, or the results of imageGetBlob() (despite one of the options being called blob).

What it DOES seem to like is a Java ByteArrayInputStream. I did the following and it worked for me.

createObject("java", "java.io.ByteArrayInputStream").init(chartImage.getImageBytes('png'))