• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Problems with CFIMAGE writetobrowser

LEGEND ,
Jun 12, 2018 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,

^ _ ^

Views

2.5K

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
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 20, 2018 Jun 20, 2018

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

...

Votes

Translate

Translate
Community Expert ,
Jun 12, 2018 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

Votes

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
community guidelines
LEGEND ,
Jun 12, 2018 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,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Jun 12, 2018 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

Votes

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
community guidelines
LEGEND ,
Jun 12, 2018 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,

^ _ ^

Votes

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
community guidelines
LEGEND ,
Jun 12, 2018 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,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Jun 12, 2018 Jun 12, 2018

Copy link to clipboard

Copied

Are you just writing it out with CFFILE?

Dave Watts, Fig Leaf Software

Votes

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
community guidelines
LEGEND ,
Jun 12, 2018 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,

^ _ ^

Votes

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
community guidelines
LEGEND ,
Jun 12, 2018 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,

^ _ ^

Votes

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
community guidelines
LEGEND ,
Jun 12, 2018 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. 

Votes

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
community guidelines
LEGEND ,
Jun 12, 2018 Jun 12, 2018

Copy link to clipboard

Copied

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

V/r,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Jun 12, 2018 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

Votes

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
community guidelines
LEGEND ,
Jun 12, 2018 Jun 12, 2018

Copy link to clipboard

Copied

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

V/r,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Jun 12, 2018 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

Votes

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
community guidelines
LEGEND ,
Jun 13, 2018 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,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Jun 13, 2018 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

Votes

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
community guidelines
LEGEND ,
Jun 13, 2018 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,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

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

Dave Watts, Fig Leaf Software

Votes

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
community guidelines
LEGEND ,
Jun 13, 2018 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,

^ _ ^

Votes

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
community guidelines
LEGEND ,
Jun 13, 2018 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,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Jun 13, 2018 Jun 13, 2018

Copy link to clipboard

Copied

That is good to know! Thanks!

Dave Watts, Fig Leaf Software

Votes

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
community guidelines
LEGEND ,
Jun 18, 2018 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,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Jun 18, 2018 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#" /> 

Votes

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
community guidelines
LEGEND ,
Jun 18, 2018 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,

^ _ ^

Votes

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
community guidelines
Community Expert ,
Jun 19, 2018 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#"/>

Votes

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
community guidelines
Resources
Documentation