yuki
yuki

Reputation: 19

Displaying image using ColdFusion from BLOB

I want to display an image from a database. I'm using data type BLOB for that image.

I've already tried #CharsetEncode(viewPoint.ppp_icons, "ASCII")#, but it didn't work.

Upvotes: 2

Views: 5976

Answers (2)

Tyler Clendenin
Tyler Clendenin

Reputation: 1489

<cfcontent reset="Yes" type="image/gif" variable="#QueryName.BlobColumn#" />

EDIT: To clarify, you would place this code in a separate template. Which you would place the call for in the src attribute of your img tag. You would pass the primary key of the database table and the new template would lookup and grab the blob column to be outputted.

I believe it would be better to keep all blob data in separate requests, because if you were trying to display many files on a page it would be best to let the page load up first rather than have the page load time wait until all blob data could be downloaded from the sql server to the coldfusion server. Reducing initial page load times is of crucial importance to usability.

As an addendum, if these files are going to be accessed frequently, then it will also be best to have the file be cache on the web server and have the separate template redirect to the cached file.

Upvotes: 0

Henry
Henry

Reputation: 32915

<cfimage action="writeToBrowser" source="#imageBlob#">

http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_i_02.html

OR... Use Data URI scheme (w/ limited browser support).

<img src="data:image/png;base64,#toBase64(imageBlob)#" />

Upvotes: 3

Related Questions