Ever wanted to save an image to a database with ColdFusion? I see this question asked quite often. I don't have a need to do this but I mocked up a quick demo or reading and writing binary data to and from a mySQL database.

The code is very simple. I read the binary data from a image. Write it to a database, read it back out and write it to the browser. I also rotate the image to show the result from the database acts just like any other image data.

You might note I made use of 2 great new features of ColdFusion 9.

1. Data source specific to the application. I no longer need to specify a datasource in my cfquery tags as I have this setup in Application.cfc.

2. On insert ColdFusion can return the autoincrement id value of the record just inserted. Eg in SQL server select @@identity does the same thing. This was available in CF8 but it was lacking and was different depending on the database type.

In ColdFusion 9 the old values still work ( so code wont break ) but we also can now use queryResult.generatedKey.

I always try include a working demo: http://railo.kukiel.net/imageinsert/

Here is the CF Code:

Here is a sample to create the mySQL table:


Also note as this gets alot of people that by default CFadmin only allows 64k to be passed from CF to the database. You will probably need to increase this value. For this example I just added 2 extra 0's ( 6.4meg ). If you don't half the image will be inserted and you will be confused as to what the image ( or other binary files ) are corrupted.

With multiple projects running locally I prefer to use virtual hosts so I can browse to http://project1.local and http://project2.local rather than http://127.0.0.1/project1 and http://127.0.0.1/project2

This is really easy in IIS ( point and click ).

Apache you have to touch some configuration files but there is alot of information out there on this.

With Resin it's also quite simple but there is far less information about this available.

I put together this walk through on the process.

And if your wondering about the performance of resin ( free edition ) Peter Bell's response should give you some confidence.

I run about 70 websites on Railo and Resin on a Win2k3 64bit server
with 8Gb of RAM and have excellent performance. Not to say it wouldn't
be better if I used the professional version.


http://groups.google.com/group/railo/msg/047ea89dea7c9385

Sample Virtual host block:



High Quality Version click here.





Related:
Setting up Resin Express.



Download and install java sdk ( I used 1.6.17 ) ( note you need the JDK not JRE )
Download glassFish
Download ColdFusion 8 or 9
Download Apache

I used Windows Server 2008 64bit but the process is the same for 32bit or Win 2k3.  It's also ( obviously ) different on linux or unix but not majorly.

When installing glassFish did not detect java home correctly so I provided the location via the cmd line.


The install is very straight forward I did not select anything unusual and just clicked through:

Once glassFish was installed I started the server:



Then browse to:  http://127.0.0.1:4848 to get to the admin console.


I choose to leave the admin with no authentication so it will just load to the console.

Before you look at the console we will need to create a ColdFusion war.  Run the ColdFusion installer and select "JEE Configuration"

This will produce the war file ready for deployment.  For me the output was c:\coldFusion9\cfusion.war

Now go back to the control panel.  Select "Applications" from the menu.  Then select "Deploy".  Choose a file from the local file system and leave the name as cfusion.


Once the application is deployed we can launch it by clicking launch button and you will see:

404 error's.  This is because there are no .cfm files if you went to /CFID/administrator you would would be at the CFADMIN.

I'll skip the CFADMIN and make a index.cfm:

Contaning:





Reload the Original page that was launched by clicking "Launch"

And ColdFusion 9 is running on GlassFish.

This is on port 8080 but I want it to run behind apache on port 80 without the /cfusion

Make sure IIS is not running. Install Apache.  Apache for windows come with all the modules you're likely to need but most are commented out.  Test to make sure Apache is runnign and http://127.0.0.1 should the standard message "It works".

Now we will setup the proxy.

Around line 110 of httpd.conf uncomment 2 modules mod_proxy.so and mod_proxy_connect.so



Also un-comment


Open {apacheInstallDir}\conf\extrahttpd-vhosts.conf

create a new vhostBlock


I created a dummy entry in the Windows host file so http://cf9gf resolves locally. I'll be using this as the test domain.

Restart apache and look for errors.


If there are no errors you should now be ready to proxy from apache to glassFish on port 80.


Done.

Now GlashFish is no longer listed here: http://www.adobe.com/products/coldfusion/systemreqs/ but it still works fine.

Also note the /flex2gateway works fine aswell.
Ever needed to compare a ColdFusion hash() directly in MS SQL? I did today and I knew I had accomplished this before but forgot how to do it. Searching the net and twitter I came to some dead end or longish solutions. I knew Steve Good and I worked this out once before but I also remember there being an easier way.

Well there is and here is where I took the solution from: http://orangepips.instantspot.com/blog/Database

The funny thing is I found this nearly a year ago and actually commented on the post just forgot all about it.





The result:

I put this together almost immediately after CF9 was released but even before then I had some people contact me to ask how CF9 runs on both Windows 7 and Windows server 2008.

Answer?

It works fine on both.

If you have ever tried to install ColdFusion 7/8 on Windows Vista after Service pack 1, Windows 7 or Windows server 2008 with IIS at one stage you have undoubtedly come across this:

"HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration.
If the page is a script, ad a handler. If the files should be downloaded, add a MIME map."


ColdFusion 9 error

Well with CF9 and Windows Server 2008 your going to get the same issue. It's actually an easy fix and almost identical to the Windows 7 / Vista solution just visually a little different here is a walk through of the installation. Note this is CF9 64 bit on Windows Server 2008 64bit and just in case you missed it 64bit is now available in ColdFusion standard:


High Quality video click here
.



BTW this will also work for CF8.

Oh and if your trying to run CF9 32 bit on Windows server 2008 64bit again don't forget 64 bit is part of standard.