A TechNote posted last week explains how to stream images in ColdFusion, and provides simple sample code.
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.
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
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?
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.
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 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.
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
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.
Good point re: security concerns. As for the content length, you can add that using CFheader:
<cfheader name="content-length" value="#ArrayLen( binaryData )#" />
<cfcontent …. />
Is there a benefit to using that technique versus using CFContent and the File attribute?
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).