Skip to main content
WolfShade
Legend
June 12, 2018
Answered

Problems with CFIMAGE writetobrowser

  • June 12, 2018
  • 2 replies
  • 3796 views

Hello, all,

I've got a problem with CFIMAGE that I could use some wisdom with.

We have a page that has a query that pulls article data from a content table and it uses a LEFT OUTER JOIN to pull media (pic or video) from a media table.

When displaying the article, if there is an associated image we insert the BLOB into an ImageNew() tag, resize it, and then display it.  Except it's not displaying.  We just get the ALT content.  Inspecting the source via browser, I can see where the CF generated IMG tag is, but there's no picture.

<cfoutput query="getarticlesbyyear">

...

     <cfif photoID neq "">

          <cfset myImage = imageNew("#thumbnail#") />

          <cfset imageResize(myImage,"150","","bilinear",2) />

          <cfimage action="writetobrowser" source="#myImage#" title="#caption#" alt="#caption#" />

     </cfif>

...

</cfoutput>

This will display in View Source:

<img src="/CFFileServlet/_cf_image/_cfimg7233696009169197587.PNG" alt="{REDACTED}" title="{REDACTED}">

Any thoughts on why this isn't working greatly appreciated.

V/r,

^ _ ^

    This topic has been closed for replies.
    Correct answer WolfShade

    A hack:

    you could bag the contents into files, then continue from there.

    <cfquery name="getImageAsBinary" datasource="cf_db">

    select image

    from imagetable1

    </cfquery>

    <cfquery name="getImageAsBase64" datasource="cf_db">

    select image

    from imagetable2

    </cfquery>

    <cfset fileWrite(expandpath('myImage1.png'),getImageAsBinary.image)>

    <img src="myImage1.png" alt="Image1">

    <cfset fileWrite(expandpath('myImage2.png'),BinaryDecode(getImageAsBase64.image,"base64"))>

    <img src="myImage2.png" alt="Image2">


    Dave Watts​ and BKBK, thank you guys for taking the time, but what both of you are suggesting would be a lot of disk I/O.

    While not thrilled with using <img src="data:image/*;base64,{blob}" />, it works.  I feel as though I've spent too much time, already, on getting CFIMAGE to work in an environment that the PTB aren't willing to allow.  So, I'm just going to move on to the next item.

    Thank you to everyone who used brain power and made decent suggestions.  I do truly appreciate all the wisdom.

    V/r,

    ^ _ ^

    2 replies

    Participant
    June 29, 2019

    hy everyone,

    i am also encountering same problem, but i think the reason of this error is CF is installed in another drive of which drive the site is placed in. As for me on Dev server it was working fine because both site and CF was installed in same directory. But on Prod it stopped working because of different directories.

    /CFFileServlet is a folder in CF temp where it save the image for 5 minutes. so i need to access this folder while writing. but i am not sure how to set it in configurations

    Any idea would be appreciated.

    Thanks

    WolfShade
    WolfShadeAuthor
    Legend
    July 1, 2019

    As I understand it, /CFFileServlet is not a physical path, but rather something that exists in RAM, so there are no settings or sandbox options for it.  We, too, have installed CF on a different partition, so maybe that's the issue.  But as hackish as my solution is, it works.

    V/r,

    ^ _ ^

    Charlie Arehart
    Community Expert
    Community Expert
    July 1, 2019

    Well, it's a servlet mapping. And cf uses a combination of mechanisms to serve and manage them which are not well-defined/documented.

    To @asif who resurrected this thread, what exactly is the "same" for you, regarding wolf's original post? Maybe there's a solution for you while there was none for him, due to his security needs. I don't expect yours are the same, just this desire to run with cf and your site on different drives.

    Honestly, the drive location for your site should have nothing to do with the drive for cf. As long as your web server knows about and is authorized to access what it needs in CF, and vice versa, the drives being different shouldn't matter for any cf processing, let alone cf image processing.

    I think you'd do better to state what is failing, and maybe the solution will be unrelated to all the above.

    /Charlie (troubleshooter, carehart. org)
    Community Expert
    June 12, 2018

    I would try to see if the original imageNew function writes out a useful image, and see what exactly you get back with your IMG element - are you getting a 404 error, an actual but useless image, or what?

    Dave Watts, Fig Leaf Software

    Dave Watts, Eidolon LLC
    WolfShade
    WolfShadeAuthor
    Legend
    June 12, 2018

    No errors in the browser, no errors in the logs (CF or webserver), just nothing.  No image.  It will display the ALT content, and that's it.  It generates the IMG tag as it should, but the "/CFFileServlet/_cf_image/_cfimg7233696009169197587.PNG" either doesn't exist, or the browser isn't getting it.  It is (AFAIK) sandboxed and allowed in CFAdmin.  But it's doing this in DEV and PRODUCTION environments.  I thought it might be a Base64 issue, so surrounded #myImage# in ToBase64(), but that errored on screen, so it's not a Base64 issue.  That's the only thing I know for fact.

    V/r,

    ^ _ ^

    Community Expert
    June 12, 2018

    You won't see anything on the file system, the image is generated (or not in your case) in memory and served directly to the browser. But what do you see when you write the response from imageNew to the file system before calling CFIMAGE?

    Dave Watts, Fig Leaf Software

    Dave Watts, Eidolon LLC