How to convert base64 to image in coldfusion?

1k Views Asked by At

I am trying to convert a base64 string into an image in ColdFusion, but it is not working. From what I have read, this can be done with the ImageReadBase64 function:

<cfset myImage = ImageReadBase64("/9j/4AAQSkZJRgABAQA..............")> 

So I tried retrieving a base64 image string from my database:

<cfquery name="GetSignImage" datasource="#application.ds#">
      select SIGNIMGBINARY 
      from   T_APPT_sign
      where  CHECKINID ='#CHECKINID#'
</cfquery>

<cfif GetSignImage.SIGNIMGBINARY neq "">
    <cfimage source="#ImageReadBase64(GetSignImage.SIGNIMGBINARY)#" name="signImage" action="resize" width="65%" height="55%">
    <cfimage source="#signImage#" action="writeToBrowser">
</cfif>

But I get this error:

The Base64 data is not in proper format. Data should be in the format understood by the <img> tag in HTML, which is "data:image/jpg;base64,[base64 data]"

Can anyone explain what I am doing wrong?

0

There are 0 best solutions below