> 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.

In a word - DON'T - you shouldn't get image data from a database for 2
reasons;
Firstly, the OS probably won't have written the file by the time the web
server requests it
Secondly, if 10 people ask for the same file, each will have to be written,
displayed and killed later

It's easier to have a reference to the file and just put that in the IMG SRC

Philip Arnold
Director
Certified ColdFusion Developer
ASP Multimedia Limited
T: +44 (0)20 8680 1133

"Websites for the real world"

**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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

Reply via email to