Search code examples
coldfusioncfimage

Stream cfcontent from an image?


Let me just say at the top that I'm not sure I truly understand what cfcontent is doing... so bear with me if this is a stupid question.

I've been using cfcontent to stream images outside of my web root to the browser. I've decided that I now want to store the image in a variable, display it, have the ability to modify it, view those modifications, and only commit the changed variable when I'm sure I like the changes. I was thinking that I could use cfcontent to somehow stream the image from a variable, and then display, modify, re-display, and save that image from the variable. My original code was simply:

<img id="photoPlaceholder" 
    src="/#application.root_name#/administration/PhotoManagement/displayPhoto.cfm?thisImage=#thisImage#" 
    width="500px" />

and displayPhoto.cfm consisted of:

<cfcontent type = "image/*" 
    file = "myPathName" 
    deleteFile = "No" />

I see that I can read the file into a variable and stream from that variable:

<cffile action="readBinary" file="myPathName" variable="fileObject" />
<cfcontent type="image/*" variable="#fileObject#" />

but if I take the intermediate step of creating an image using

<cfimage source="fileObject" name="myImage" />
<cfcontent type="image/*" variable="#myImage#" />

then I get an attribute validation error.

Any thoughts?


Solution

  • ImageGetBlob()?

    If you think about it - this makes sense. Image variables aren't binary data in ColdFusion. While they may store binary data, ColdFusion wraps up the data in a new "Image" variable type.

    http://www.coldfusionjedi.com/index.cfm/2007/9/14/Serving-up-CFIMages-via-Image-Tags-and-a-NonCF-Friday-contest

    If you're using CF9, you can try writing the image to the RAM:// drive first, serve it, and delete from RAM.