Wednesday, December 03, 2008    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Aug 2008 >>
S M T W T F S
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

Search

Categories
 • Acrobat (2) [RSS]
 • Adobe (71) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (57) [RSS]
 • AdobeMAX09 (1) [RSS]
 • AIR (148) [RSS]
 • Appearances (140) [RSS]
 • Books (69) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1179) [RSS]
 • Data Services (20) [RSS]
 • Fish Tank (2) [RSS]
 • Flash (112) [RSS]
 • Flex (385) [RSS]
 • Home Automation (3) [RSS]
 • Jobs (101) [RSS]
 • JRun (13) [RSS]
 • Labs (29) [RSS]
 • LiveCycle (23) [RSS]
 • MAX (189) [RSS]
 • Regular Expressions (15) [RSS]
 • RIA (13) [RSS]
 • SQL (38) [RSS]
 • Stuff (506) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (140) [RSS]
 • Wireless (100) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
August 26, 2008

TechNote Explains How To Stream Images In ColdFusion

A TechNote posted last week explains how to stream images in ColdFusion, and provides simple sample code.

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
Is there a benefit to using that technique versus using CFContent and the File attribute?
# Posted By Ben Nadel | 8/26/08 12:05 PM
They used a cffile in the example, but it looks like it could be easily altered to pull from a database. I am also interested in knowing the benefit.
# Posted By Randy Johnson | 8/26/08 1:58 PM
@Randy,

The CFContent tag has a Variable attribute that allows you to pass in a binary variable:

<cfcontent type="image/jpeg" variable="#qData.blob#" />

I feel like the advent of CFContent got rid of many of the needs to go directly into the response object to do things.
# Posted By Ben Nadel | 8/26/08 2:10 PM
I'm doing this with cfcontent all the time, what's the benefit of "streaming" images instead? With cfcontent you block one of the listeners ("simultanious requests") while the image is being transferred to the client, is this perhaps different with the streaming example?
# Posted By Wim | 8/26/08 2:14 PM
If I had the Maximum number of simultaneous requests set to 8 on my server and my site was streaming 8 images to users with a dialup connection that would clog the machine right? That problem wouldn't exist using the file system.

-Randy
# Posted By Randy Johnson | 8/26/08 2:23 PM
@Randy,

Whether you are writing to the Response object or using the CFContent tag, I *assume* that it still keeps the single thread busy with the binary data transfer. After all, something still needs to be flushing the response to the client.

I believe the only way to get around this is to pass of the file request to a static file server (I think something that Apache can do inherently, but not IIS).
# Posted By Ben Nadel | 8/26/08 2:29 PM
I wonder if this would fix (and I should test it) the bug with serving up images that are virgin - ie - make from scratch with cfimage (as opposed ot reading in a real file). I know Jason Delmore had posted a fix for that a while ago.
# Posted By Raymond Camden | 8/26/08 2:57 PM
@Ray,

I think the problem there is that on a CFImage-created binary, there is no "file type" until the image is saved. Therefore, I think there are problems streaming the underlying BLOB data because it has no particular encoding?? I am only guessing here, but I think that is the problem I have run into.

If that *is* the problem, I think you will still encounter the same issue - that no compression / file type is defined..... but totally guessing here :)
# Posted By Ben Nadel | 8/26/08 3:03 PM
The difference between the code in the tech note and cfcontent is that with cfcontent the server sends Connection:close to the client, and with the code in the tech note, it sends Content-Length. I determined this with the HTTP-Headers plugin for firefox. I'm not sure I understand the difference, or why I might use one and not the other, but there it is.

I tested this with a very large image, and both techniques loaded the image in the same amount of time.

One of the servers I have access to has sandbox security turned on. cfcontent is not allowed, but cffile is allowed, and the code in the technote works on that server. So there's one advantage. If you're allowed to use cffile but not cfcontent, this is a workaround.
# Posted By Chris | 8/26/08 3:45 PM
@Chris,

Good point re: security concerns. As for the content length, you can add that using CFheader:

<cfheader name="content-length" value="#ArrayLen( binaryData )#" />
<cfcontent .... />
# Posted By Ben Nadel | 8/26/08 3:48 PM

  © Copyright 1997-2008 Ben Forta, All Rights Reserved