Serving an image from secure webcam
I had a problem today, where I needed to get an image from a webcam and display it on a website. Sounds simple enough, but the url of the webcam contained the username, password and port so it had to be hidden. For example:
http://username:password@somewhere.com:1234/SnapshotJPEG?Resolution=320x280
My first though was to do
ImageNew( url )
But this returned the error:
The /snapshotjpeg image format is not supported on this operating system.
Use GetReadableImageFormats() and GetWriteableImageFormats() to see which image formats are supported.
That leaves cfhttp:
<cfhttp url="http://somewhere.com:1234/SnapshotJPEG?Resolution=320x280"
username="username"
password="password"
result="webcam">
webcam.filecontent contains a Java object of type java.io.ByteArrayOutputStream. As the cfimage tag can accept a source of Base64 byte arrays, I simply called the toByteArray() of the Java object.
Here is the final solution:
<cfhttp url="http://somewhere.com:1234/SnapshotJPEG?Resolution=320x280"
username="username"
password="password"
result="webcam">
<cfimage action="writeToBrowser"
source="#cfhttp.filecontent.toByteArray()#">
As a side note, I did find that you can't pass the username and password in the url. If you do then you get a connection failure with the error:
I/O Exception: unknown protocol: username
- Posted in:
- ColdFusion


It's not properly "secure" though as the username and password are being passed over http.
Comment by James Buckingham – April 30, 2010
Comment by John Whish – April 30, 2010