0

I am saving images in my db field like data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAg......

When I display the images using <cfimage action="writeToBrowser" source="#myField#"> on a normal page it works fine. When using in a cfdocument it doesn't work. I have seen some similar issues but haven't seen any of them work for me. I tried <img src="#myField#" /> but without any luck. Anyone get this working?

Thanks

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
Paul
  • 11
  • The HTML renderer in `` tends to be very dates. I wonder if CF2018 is any better. – James A Mohler Nov 04 '19 at 18:14
  • 1
    Does this answer your question? [Image is not displaying in cfdocument pdf for coldfusion 10](https://stackoverflow.com/questions/18074454/image-is-not-displaying-in-cfdocument-pdf-for-coldfusion-10) – Dan Bracuk Nov 04 '19 at 20:11
  • Its CF2018 im trying it on actually. Going try and create images locally from the base64 value and see how that goes. – Paul Nov 04 '19 at 22:48

2 Answers2

1

When I've seen this before it was the CF 'browser' on that server not being able to connect to the /CFFileServlet/_cf_image/_cfimg-...PNG URL over loopback on that box. The exact cause and solution will depend upon how your web server, site config, SSL, firewall, routing, DNS are all set up.

Have you looked at error logs in CF Admin for the requests with the image errors? If you get no clues there then one way to help diagnose where it's failing is to wrap your <cfimage action="writeToBrowser" code in a <cfsavecontent> or <cfxml> tag to extract the src URL of the temp image written, and then see what result you get if you try and hit that same URL with a cfhttp call from the server - you should hit the same problem that cfdocument is getting, but you'll be able to dump out any errors to troubleshoot.

Depending upon the cause in your case, one of the following methods should work:

  1. if the CF browser is unable to resolve its own hostname then add the site's domain to your server's local HOSTS file;
  2. if a different vhost / IIS Site is being used when navigated to from the box itself than from the outside world, then make sure that the /CFFileServlet/ mappings are still visible on that site;
  3. if cfdocument/cfhttp get SSL errors, ie if your site is using (or rewriting http to) https for these image requests, then make sure that your site's certs are trusted by your CF keystore;
  4. Check your firewall config isn't blocking these internal requests.

Other lesser workarounds if you don't have access to solve above environment type issues:

a) rewrite the src URL from a relative URL to an absolute file:/// URL when used with cfdocument only.

b) if there is a localhost mapping to your site (on port 80 or otherwise) that is visible on your server, then you can try rewriting the src URL to use that instead of the FQDN.

c) instead of using writeToBrowser, write the cfimage output to a path of your choice that you can prove works with cfdocument/cfhttp and output your own img tag to serve the image from that path.

In my experience you'll see a lot of posts around about cfdocument and image paths and using localUrl=true - but where cfimage writeToBrowser is involved I have always found I needed to use localUrl=false and rely on absolute URLs.

Sev Roberts
  • 1,295
  • 6
  • 7
  • 1
    Thanks for the replies. Ended up going the following route which worked:- ` ` – Paul Nov 06 '19 at 09:29
  • Thanks! I encountered the same problem after someone switched our reporting to https (i.e. images not appearing on PDFs anymore). Your clue about SSL pointed me in the right direction. – jj2 Jan 28 '20 at 00:11
0

Just use isBase64="yes" attribute in your cfimage tag.Like this,

<cfimage isBase64= "yes" action = "writeToBrowser" source="#myField#" >