Copy link to clipboard
Copied
Hello everybody,
I try to create a new image with a blob coming from a database, but when I execute the following instructions, ColdFusion returns me an error message "Decoder cannot decode input."
<cfquery name="qData" datasource="MyDS">
SELECT a.BLOB_DOC
FROM TOFFDOC a
WHERE a.CLE_DOC = #URL.cledoc# AND
a.TYP_DOC = 'JPG'
</cfquery>
<cfset myOriginalImage=ImageNew(qData.blob_doc)>
I use Coldfusion 9.0.1.274733 enterprise edition on a Windows server 2003 and Sysbase Sql Anywhere 11 for the database.
An idea ?
Copy link to clipboard
Copied
Does your CF datasource have the BLOB option enabled?
See:
http://help.adobe.com/en_US/ColdFusion/9.0/Admin/WSc3ff6d0ea77859461172e0811cbf364104-7fe0.html
Copy link to clipboard
Copied
Yes, I checked the CLOB and BLOB options in the advanced settings of the datasource
Copy link to clipboard
Copied
If you view the blob field's contents is the result a base 64 encoded string? If so you may need to wrap a call to the ToBinary function around the field when using it is a parameter for the ImageNew function.
Copy link to clipboard
Copied
Hi, Thanks for your answer
Sorry, I forgot to specify that the code works fine when I retrieve a small BLOB image (less than 400k), for the bigger images it raises an exception. I also tried to use the ToBase64() conversion function but I always have the same error.
Regards
Copy link to clipboard
Copied
Have you verified that the BLOG being retrieved is a valid image? Can you open and view the image file if the image is saved to the file system with CFFILE? Is the image in a format compatible with ImageNew()?
Copy link to clipboard
Copied
The retrieved image is a JPG format.
I can create a new image using the ImageNew() function only for image with a size less than 400k.
Actually, I am not at my office and I couldn't test using CFFILE. I will test Monday
Thanks for your help
Copy link to clipboard
Copied
I can browse the image when I export this one with Sybase central
<cfoutput>
<cffile action="readbinary" file="...\894170cf31d9e327bc074e050e2cac4a.jpg" variable="myImage">
<cfimage action="writeToBrowser" source="#myImage#">
</cfoutput>
But when I try to use ImageNew() with a BLOB field, CF returns me "Decoder cannot decode input." for the same image
<cfquery name="qData" datasource="MyDs">
SELECT a.BLOB_DOC FROM TOFFDOC a
WHERE a.CLE_DOC = #URL.cledoc# AND
a.TYP_DOC = 'JPG'
</cfquery>
<cfset myOriginalImage=ImageNew(qData.blob_doc)>
Copy link to clipboard
Copied
What happens if you use CFFILE to write the contents of BLOB_DOC to disk? Is the resulting file correct?
Copy link to clipboard
Copied
Yes it works fine when I use the CFFILE syntaxe
<cffile action="write" file="#rootLarge##qBlob.IMG_CLE_DOC#.jpg" output="#qBlob.blob_doc#" >
It's really strange
Copy link to clipboard
Copied
Have you tried writing the image to the file system, then using the file system as the source for the ImageNew function call?
Copy link to clipboard
Copied
Yes, and it works fine
<cffile action="readbinary" file="...\894170cf31d9e327bc074e050e2cac4a.jpg" variable="binObj">
<cfset myImage=ImageNew(binObj)>
<cfimage action="writeToBrowser" source="#myImage#">
Copy link to clipboard
Copied
Actually, I found this workaround
<cftry>
<cffile action="write" file="#rootLarge##qImages.IMG_CLE_DOC#.jpg" output="#qImages.blob_doc#" >
<cffile action="readBinary" file="#rootLarge##qImages.IMG_CLE_DOC#.jpg" variable="myOriginalImage">
<cfset myOriginalImage=ImageNew(myOriginalImage)>
<cfset myWidth=#ImageGetWidth(myOriginalImage)#>
<cfset myHeight=#ImageGetHeight(myOriginalImage)#>
<cfif myWidth gt 900 or myHeight gt 540>
<cfset ImageScaleToFit(myOriginalImage,900, 540)>
</cfif>
<cfimage source="#myOriginalImage#" action="write" destination="#rootLarge##qImages.IMG_CLE_DOC#.jpg" overwrite="yes" quality="1">
<cfcatch type="any"><cfset errorMessage=errorMessage&"#cfcatch.message#<BR>"></cfcatch>
</cftry>