Aliaspooryorik
ColdFusion ORM Book

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

 


2 comments

  1. That's very cool John :-).

    It's not properly "secure" though as the username and password are being passed over http.

    Comment by James Buckingham – April 30, 2010
  2. @James, OK so it's not secure if you're sniffing http traffic, but I don't think the client wants to install an SSL cert on their home PC :)

    Comment by John Whish – April 30, 2010

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.

Please subscribe me to any further comments
 

Search

Wish List

Found something helpful & want to say ’thanks‘? Then visit my Amazon Wish List :)

Categories

Recent Posts