Ask Ben: Streaming Binary Data From The Database (BLOB) To The User Using ColdFusion

<!--- Param URL data. --->
<cfparam name="URL.id" type="numeric" default="0" />
 
 
<!--- Query for hottie record and pull back image binary. --->
<cfquery name="qHottie" datasource="#REQUEST.DSN#">
	SELECT
		h.id,
		h.name,
		h.photo
	FROM
		hottie h
	WHERE
		h.id =
			<cfqueryparam
				value="#URL.id#"
				cfsqltype="cf_sql_integer"
				/>
</cfquery>
 
 
<!--- Set the header values. --->
<cfheader
	name="content-length"
	value="#ArrayLen( qHottie.photo )#"
	/>
 
<!---
	Set the file name of the inline graphic to be the name
	of the hottie record.
--->
<cfheader
	name="content-disposition"
	value="inline; filename=#qHottie.name#"
	/>
 
<!--- Stream the binary image data to the user. --->
<cfcontent
	type="image/*"
	variable="#qHottie.photo#"
	/>

For Cut-and-Paste