?
Solved

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

Posted on 2012-12-26
8
Medium Priority
?
437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1000 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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
This article discusses how to create an extensible mechanism for linked drop downs.
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)
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 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