TechNote Explains How To Stream Images In ColdFusion

11 responses to “TechNote Explains How To Stream Images In ColdFusion”

  1. Randy Johnson Avatar
    Randy Johnson

    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.

  2. Ben Nadel Avatar
    Ben Nadel

    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

  3. Wim Avatar

    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?

  4. Randy Johnson Avatar
    Randy Johnson

    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.

  5. Ben Nadel Avatar
    Ben Nadel

    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.

  6. Raymond Camden Avatar
    Raymond Camden

    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.

  7. Ben Nadel Avatar
    Ben Nadel

    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 o

  8. Chris Avatar

    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.

  9. Ben Nadel Avatar
    Ben Nadel

    Good point re: security concerns. As for the content length, you can add that using CFheader:
    <cfheader name="content-length" value="#ArrayLen( binaryData )#" />
    <cfcontent …. />

  10. Ben Nadel Avatar
    Ben Nadel

    Is there a benefit to using that technique versus using CFContent and the File attribute?

  11. Steve Sommers Avatar
    Steve Sommers

    Any idea how to modify this to work with large blobs? By "large" I mean blobs that must be read in chunks using readtext (MSSQL).

Leave a Reply