Solved

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

Posted on 2012-12-26
8
420 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 75

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 75

Expert Comment

by:käµfm³d 👽
ID: 38721935
Looks like I encode them as base 64?
Yes.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)

830 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