Ask a Question related to Coldfusion Database Access, Design and Development.
-
Duke Snyder #1
Re: Storing and retrieving image files in a database
hi JerkyRobot I can see no one answered your question. here is the answer.
a few things you will have to do before this will work. 1) you need to tweak
your DSN in the Advanced settings. make sure the CLOB (enable long text
retrieval) is checked. 2) make sure the table column you are storing the data
in is longtext or comparable. keep in mind this is Linux and MySQL. <!---
first we read the binary file ---> <CFFILE ACTION='ReadBinary'
FILE='/your_path/your_image.jpg' VARIABLE='aBinaryObj'> <CFIF
isBinary(aBinaryObj)> <CFSET base64 = toBase64(aBinaryObj)> <CFELSE>
<CFABORT showerror='The file does not appear to be a binary file'> </CFIF>
<!--- if everything is cool, we insert the data ---> <CFQUERY
datasource='your_DSN'> INSERT INTO your_table (your_field) VALUES
(<CFQUERYPARAM VALUE='#base64#' CFSQLType='CF_SQL_CLOB'>) </CFQUERY> <!---
now to get the data back, just query the DB ---> <!--- now we use cffile agian
to convert it back to an image ---> <CFFILE action='WRITE'
file='/your_path/your_image_name.jpg' output='#toBinary(getImg.attachment)#'
addnewline='No'> <!--- there you go. this will work for any binary file
(.exe, .zip etc.) --->
Duke Snyder Guest
-
Database Storing
I have created and asp form and connected to a sql database on dw. What is the next step for getting the submit button to store the form info in the... -
MySQL Database not retrieving the full database
Hi, I am using MySQL and PHP for my repository. It has 500+ records. till now it was displayiing all records in the database, but since from one... -
Storing and Retrieving Info in Access
I'm not sure if this is even the best place to ask this question, but here goes: my site is hosted by a third party on a Win2K platform and there... -
Storing and retrieving arrays using Berkeley DB (Sleepycat)
Hi all, I have experience with PHP, but I am totally newbie on Perl. I need to use Berkeley DB to store/retrieve some records. The samples I... -
Storing/Retrieving/Executing Php
I want to creating an application where all my php(with html) is stored in the database. So my index.php would find the appropriate the php file... -
Superflyc #2
Re: Storing and retrieving image files in a database
another way to do it, assuming it's been stored as a BLOB (or whatever your
database calls binary info) is to do a simple select query on it, then output
it to the browser like so: <cfcontent type='image/jpg'>
<cfoutput>#toString(your_image_field_here))#</cfoutput> CFCONTENT and CFHEADER
have lots of cool uses.
Superflyc Guest
-
shahzad #3
Re: Storing and retrieving image files in a database
Hi Duke Snyder, I copied your code and changed CF_SQL_CLOB to CF_SQL_BLOB and
tried to run it but i got a following error 'rror casting an object of type
to an incompatible type. This usually indicates a programming error in Java,
although it could also mean you have tried to use a foreign object in a
different way than it was designed.' I am using CFMX 7 and oracle 9i is the
db. I also tried to run the code using CF_SQL_CLOB but that gave me the
following error 'Macromedia][Oracle JDBC Driver]Value can not be converted to
requested type.' any ideas? thank you
shahzad Guest
-
shahzad #4
Re: Storing and retrieving image files in a database
nevermind, someone helped me to fix the problem. For reference for the others,
i shouldn't be converting the image to base64 because my datatype for the
column in the db is BLOB. if it was CLOB, then i would convert it to base64
shahzad Guest



Reply With Quote

