Is there a way you can display an image from a database in ColdFusion?
(no need to start with the reasons not to have images in a database,
I am way past that issue, it really is fine to have them in the
database in this particular application).
I want to be able to have IMG tags in my HTML that are like
IMG SRC="/getimage.cfm?imageid=3" and then have getimage.cfm
get the binary image data from the database and give it to
the browser. Right now the image data is stored in Base64
format in a text type field in the DB. I was trying to use this
code:
<CFSETTING ENABLECFOUTPUTONLY="Yes" SHOWDEBUGOUTPUT="No">
<CFQUERY NAME="getimg" DATASOURCE="dsn">
SELECT image from image WHERE imageid = <CFQUERYPARAM VALUE="#Attributes.imageid#"
CFSQLTYPE="CF_SQL_INTEGER">
</CFQUERY>
<CFCONTENT TYPE="image/jpeg">
<CFOUTPUT>"#ToBinary(getimg.image)#</CFOUTPUT>
But this gives me this error: Expression result cannot be converted to a string.
Expressions used inside tags like CFOUTPUT, CFQUERY, CFMAIL, etc. must evaluate to a
value that can be converted to a string for output or dynamic text accumulation
purposes. Complex objects, such as queries, arrays, and COM/DCOM objects, cannot be
represented as strings.
I'm just about ready to just write it in Perl. Thanks for any help.
Ryan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists