Solved

Printing <img> to ColdFusion web app client from server side JSON

Posted on 2012-12-26
8
400 Views
Last Modified: 2012-12-28
I'm working with ColdFusion 9 and JQuery datatables.

I'm using the JQuery databasles server side data capability to page through large datasets.  I want to display images in one the fields of the dataset.  My images reside outside the webroot for security reasons.  

How can I pull the image from the location on the server drive to display in the table.  I know I could use cfimage except for the data be returned to the client is JSON.

Is there a way to temporarily load the image in the browser memory so that the img tag can access it?
0
Comment
Question by:HyperBPP
  • 4
  • 2
  • 2
8 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 38721616
How large are the images? Perhaps a data URI could suffice?
0
 
LVL 6

Author Comment

by:HyperBPP
ID: 38721918
They're small.  ~7kb.  Need to display as ~20x15px or so.  Looks like I encode them as base 64?
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 38721935
Looks like I encode them as base 64?
Yes.
0
 
LVL 6

Author Comment

by:HyperBPP
ID: 38722185
Ok, I'm doing the below, and it works except for the color of the icon gets changed.  Almost like a color negative.  Any thoughts?

<cfset thisFile = '#myIcons#unitIcon/#qFiltered.ICON#'>
	
	<cfimage
		name="photo"
		action="read"
		source="#thisFile#"
		/>
	
	<cfset qFiltered.ICON = '<img
src="data:image/*;base64,#toBase64( photo )#"
height="20"/>'>

Open in new window

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 52

Expert Comment

by:_agx_
ID: 38722368
What kind of image - jpg, png, ..?

As a test, do a <cfimage action="writeToBrowser" ...> of #photo# on a separate page. Are the image colors still wrong? Edit  If yes, it suggests a problem with the image itself. Try the same test with a few other images.  If no, it's a problem with the base64 function.
0
 
LVL 6

Author Comment

by:HyperBPP
ID: 38723846
@_agx_

They are .png.

Tried the <cfimage action="writeToBrowser" ...> which worked fine.  If it's a problem with the base64 function what can I do?  Do I use a different function, or are my parameters wrong?

Thanks!
0
 
LVL 6

Author Comment

by:HyperBPP
ID: 38723936
And another tidbit of info.  Just found that the images work in FireFox (with the coloring wrong) but do not display in Internet Explorer at all.
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 250 total points
ID: 38724064
Sorry I should've said "suggests a problem with the base64 function" not that it definitely *is* that function.  Something could be going wrong with the transfer through jquery.  You need to rule that out.  Add the same "<img> tag directly to your test page. Does it display correctly?

ie   <cfoutput>
          <img src="data:image/*;base64,#toBase64( photo )#" height="20"/>
     </cfoutput>

You could also try reading the image binary and converting that to base64 - instead of using cfimage.

http://www.bennadel.com/blog/2002-Creating-Base64-Encoded-Data-URLs-For-Images-In-ColdFusion.htm
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now