Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display Active Directory jpegPhoto with ColdFusion?

I'm creating a company directory using our existing Active Directory information. I'm able to pull all the data I need, but I wanted to use Active Directory for the photo as well.

I found this snippet of code on this blog: http://plus10.blogspot.com/2008/02/coldfusion-cfldap-display-images-stored.html

    <!--- imageFile.cfm --->

<cfsilent>

<cfldap action="QUERY"
name="ldap"
attributes="jpegPhoto"
start="dc=[yourdc],dc=com"
filter="sAMAccountName=[loginname]"
server="[yourserver]"
username="[username]"
password="[password]">

<cfscript>
     ldapPhoto = toString(ldap.jpegPhoto);
     ldapPhoto = binaryDecode(ldapPhoto,"base64");
</cfscript>

</cfsilent><cfcontent type="image/jpeg" variable="#ldapPhoto#">


<!--- to display the image on a page --->

<img src="imageFile.cfm" width="100" height="125" alt="">

I plugged in all my server data and I get the error

The image "....imagefile.cfm" cannot be displayed because it contains errors

Why isn't the image displaying? and how can I correct the code?

I did a <cfdump> on the query and it just shows as "jpegPhoto" not binary data.

I can't post the actual page because it is on an internal network only.

like image 703
Adreanna Dianna Pedersen Avatar asked Oct 31 '13 22:10

Adreanna Dianna Pedersen


1 Answers

Note, the poster answered her own question. The cfcontent and img tags should be replaced with a cfimage tag using the source attribute and action="writeToBrowser"

like image 139
efreed Avatar answered Oct 07 '22 14:10

efreed