Highlighted

Problems with CFIMAGE writetobrowser

LEGEND ,
Jun 12, 2018

Copy link to clipboard

Copied

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,

^ _ ^

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,

^ _ ^

Views

1.3K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Problems with CFIMAGE writetobrowser

LEGEND ,
Jun 12, 2018

Copy link to clipboard

Copied

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,

^ _ ^

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,

^ _ ^

Views

1.3K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 12, 2018 0
Adobe Community Professional ,
Jun 12, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
LEGEND ,
Jun 12, 2018

Copy link to clipboard

Copied

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,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
Adobe Community Professional ,
Jun 12, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
LEGEND ,
Jun 12, 2018

Copy link to clipboard

Copied

I'm trying to set it so that the images will be written in a tmp folder.  If that works, I'll report back. 

Thank you,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
LEGEND ,
Jun 12, 2018

Copy link to clipboard

Copied

Now I'm getting "ByteArray objects cannot be converted to strings" when trying to save files in a tmp folder.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
Adobe Community Professional ,
Jun 12, 2018

Copy link to clipboard

Copied

Are you just writing it out with CFFILE?

Dave Watts, Fig Leaf Software

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
LEGEND ,
Jun 12, 2018

Copy link to clipboard

Copied

Trying to use CFFILE to save to a tmp folder so I can look at whether or not what I'm getting from the database is an image and whether or not CF is able to work with it.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
LEGEND ,
Jun 12, 2018

Copy link to clipboard

Copied

Okay, instead I'm taking the variable "myImage" and outputting #IsImage(myImage)#, and they are all saying YES.  So, I'm getting an image from the database, but CFIMAGE can't writetobrowser with the image object.

Dangit. 

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
LEGEND ,
Jun 12, 2018

Copy link to clipboard

Copied

I'm checking with our SA on whether or not we are using URL rewrites (Ben Nadel article).

V/r,

^ _ ^

UPDATE:  No, we are not using URL rewrites. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
LEGEND ,
Jun 12, 2018

Copy link to clipboard

Copied

I wonder: do I need to create a mapping in CFAdmin for /CFfileServlet ?

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
Adobe Community Professional ,
Jun 12, 2018

Copy link to clipboard

Copied

No, and I don't even think you could if you wanted to. This is a "fake" URL that's generated automatically and resolved automatically using the settings in web.xml. But it does mean that your /jakarta virtual mapping has to be properly set up. You can't rely on ISAPI mappings to handle this, because they rely on file extensions.

Dave Watts, Fig Leaf Software

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
LEGEND ,
Jun 12, 2018

Copy link to clipboard

Copied

So, I should investigate backing up and editing web.xml?

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
Adobe Community Professional ,
Jun 12, 2018

Copy link to clipboard

Copied

You should definitely back it up I guess. I don't know if editing it would help you, though. The way that servlet URLs work is, they're matched against patterns in web.xml. But for that to work, the web server has to know to send the servlet URL to CF in the first place, and it does that using the /jakarta virtual mapping that gets set up along with the ISAPI mapping when you run the connector setup. The thing is, I can't imagine you'd get a 200 response if that URL just wasn't responding, so I'm hesitant to say that's where your problem is.

Dave Watts, Fig Leaf Software

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 12, 2018 0
LEGEND ,
Jun 13, 2018

Copy link to clipboard

Copied

Yeah, I looked at the web.xml and my eyes crossed and glazed over.    So, I won't be editing anything, there.

I just don't get it.  The database is providing an image object, I just don't understand what cfimage is or is not trying to do with it, or where the process is breaking down.  And unfortunately the site is a restricted site, so I can't provide a URL for anyone to look at it.

😕

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 13, 2018 0
Adobe Community Professional ,
Jun 13, 2018

Copy link to clipboard

Copied

I'm kind of grasping at straws here without being able to look at anything - I'm sure you know the feeling!

If you look at the image through, say, Chrome Developer Tools, do you see anything at all?

Is the disk full? This can cause all sorts of otherwise hard-to-diagnose issues.

Dave Watts, Fig Leaf Software

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 13, 2018 0
LEGEND ,
Jun 13, 2018

Copy link to clipboard

Copied

Looking in FF Dev Tools (Inspect Element), it shows what I posted in my original post - the img tag with a src value that begins "/CFFileServlet/" and ends in ".PNG".  No error messages, but no image.  Just the ALT content appears where the image is supposed to.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 13, 2018 0
Adobe Community Professional ,
Jun 13, 2018

Copy link to clipboard

Copied

I'm sorry, I'm out of ideas at this point.

Dave Watts, Fig Leaf Software

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 13, 2018 0
LEGEND ,
Jun 13, 2018

Copy link to clipboard

Copied

I appreciate your time, Dave.  Maybe someone else will poke their head in here and think of something we haven't.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 13, 2018 0
LEGEND ,
Jun 13, 2018

Copy link to clipboard

Copied

I did some more Googling (can't believe that's actually a 'thing') and found the following that I have forwarded to our SA.  I'll let you know if it worked.

===========================================

After much trial and error and looking at the post on Ben Nadel's site, I finally got this working. I decided to put this in the mod_jk.conf file that the CF10 install creates so I could keep all the cf specific stuff together. At the bottom of the file I added an alias and set the permissions on the location as so:

Alias /CFFileServlet "/Applications/ColdFusion10/cfusion/tmpCache/CFFileServlet"
<Directory "/Applications/ColdFusion10/cfusion/tmpCache/CFFileServlet">
  Options Indexes FollowSymLinks
  AllowOverride None
  Order allow,deny
  
Allow from all
</Directory>

After doing that, all my images lit right up.

===========================================

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 13, 2018 0
Adobe Community Professional ,
Jun 13, 2018

Copy link to clipboard

Copied

That is good to know! Thanks!

Dave Watts, Fig Leaf Software

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 13, 2018 0
LEGEND ,
Jun 18, 2018

Copy link to clipboard

Copied

Unfortunately, we'll never know if this will work, or not.  It violates the STIG, so the PTB will not allow it. 

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 18, 2018 0
Adobe Community Professional ,
Jun 18, 2018

Copy link to clipboard

Copied

What about something like this:

<cfset myImage = imageNew(getArticlesByYear.imgColumnName) /> 

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

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 18, 2018 0
LEGEND ,
Jun 18, 2018

Copy link to clipboard

Copied

That's what was in place that isn't working.  The STIG is set so high that CFIMAGE doesn't work.  At least, that's what I can tell, so far.

My workaround is to grab the BLOB from the database, ToBase64() it, and use it as part of the img src:

<img height="150" src="data:image/*;base64,#toBase64(myImage)#" />

Kind of hackish, but it works.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 18, 2018 0
Adobe Community Professional ,
Jun 19, 2018

Copy link to clipboard

Copied

OK.

The following test (based on a MySQL database) worked without any issues.

<cffile action="readbinary" file="C:\ColdFusion2018\cfusion\wwwroot\workspace\cf_project\test.png" variable="testImage">

<cfset imageAsBase64 = toBase64(testImage)>

<!--- Save image to DB as BLOB --->

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

insert into imagetable1(image) values(<cfqueryparam value="#testImage#" cfsqltype="cf_sql_blob">)

</cfquery>

<!--- Save image to DB as Base64 --->

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

insert into imagetable2(image) values(<cfqueryparam value="#imageAsBase64#" cfsqltype="cf_sql_clob">)

</cfquery>

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

select image

from imagetable1

</cfquery>

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

select image

from imagetable2

</cfquery>

<cfset myImage1 = imageNew(getImageAsBinary.image) />

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

<cfimage action="writetobrowser" source="#myImage1#"/>

<cfset myImage2 = imageNew(imageReadBase64(getImageAsBase64.image)) />

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

<cfimage action="writetobrowser" source="#myImage2#"/>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2018 0
LEGEND ,
Jun 19, 2018

Copy link to clipboard

Copied

In a normal corporate environment, or personal dev environment, that will work.  But this is DoD, and the STIG has security settings so high that we can't use CFIMAGE.  At all.  For anything.  So, I unfortunately have to use hack-ish methods to get things done.  (I call it hack-ish, not that I'm hacking anything.)

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2018 0
Adobe Community Professional ,
Jun 19, 2018

Copy link to clipboard

Copied

That sounds curious. I mean, cfimage can do a lot of things that I can’t see all being related to possible security issues.

More important, I don’t see any mention of anything related to “image” at all (the tag or functions or just that term) in the online STIG:

https://www.stigviewer.com/stig/adobe_coldfusion_11/

Is what you’re being told about the details of some one there? If so, which one. This is just interesting to hear about, and you seem firm in your conviction about it. Then again, sometimes people are told things by folks they work with and they accept those as facts. If this may help you press the case and find a better solution for your need, then perhaps my asking this will have helped you.

/charlie

PS Can you tell us how you prefer us to refer to you? I am always torn about whether to address you as “wolf” or “wolfshade” or “ws” or I’d use your name if it was shown, but I know some people prefer not to show their names in their profile (such that appears on each reply, like mine does). If you shared it, I would try to remember it, but I will understand if you prefer not to share it here. Apologies if you’ve told me before and I have just forgotten.

/Charlie (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 19, 2018 0
LEGEND ,
Jun 20, 2018

Copy link to clipboard

Copied

Hi, Charlie, always good to see you online.

Yes, I am blaming the STIG without _FULL_ knowledge of everything involved, but I've been here long enough that it would not surprise me one bit if the STIG is responsible.

But there are so many layers of security that I am not familiar with that any of them could be the culprit.  It could be a CF security setting, or it could be the security of just about any stack layer involved.  I only just recently learned that our security is as thick, wide, and tall as it is because we are the most targeted organization within DoD.  So it really doesn't come as a surprise.

I've been here long enough that when stuff like this happens, I just count to ten, let out a soft sigh, and start to figure out a workaround, because there's nothing I can do to change it.  As the old addage goes, "It is what it is."  The PTB are an unmovable object, and I am not an unstoppable force.

As far as referring/addressing me, I don't really have a preference.  Wolf, WolfShade, ws, it's all good.  And, yes, for a variety of reasons, not the least of which is because I am a federal contractor, I prefer to remain as anonymous as possible.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 20, 2018 0
New Here ,
Jun 29, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 29, 2019 0
LEGEND ,
Jul 01, 2019

Copy link to clipboard

Copied

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,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 01, 2019 0
Adobe Community Professional ,
Jul 01, 2019

Copy link to clipboard

Copied

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 (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 01, 2019 1