Question
Store / Retrieve images from Database with ColdFusion
I would like to store / retrieve images in a Microsoft SQL 2000 server. Can this be done?
<!----------- STORE in database ------------------->
<cffile action = "readBinary" file = "C:\inetpub\wwwroot\photos\somewhere.jpg" variable = "aBinaryObj">
<CFQUERY NAME="storeImage" DATASOURCE="#DATA_SOURCE#">
UPDATE tImageTable
SET myimage = '#aBinaryObj#'
WHERE myimage_id = 1
</CFQUERY>
<!------------------ RETRIEVE IMAGE -------------------->
<CFQUERY NAME="getImage" DATASOURCE="#DATA_SOURCE#">
SELECT myImage
FROM tImageTable
WHERE myimage_id = 1
</CFQUERY>
<!--- Output binary object to JPEG format for viewing. --->
<cffile action="write" file = "c:\files\updates\somewhereB.jpg" output = "#getImage.myimage#">
<!--- HTML to view image. --->
<img src="C:\files\updates\somewhereB.jpg">
Thanks
