I am now updating images within LDAP by using CFHTTP to call an ASP page...
> As you say, it appears something might be lost in translation between cfldap
> and the underlying Java code.
>
While looking into Java for a solution, a smart co-worker (thanks Peter
Jacoby!) wrote a .NET script that updates the photo directly in its
binary form.
COLDFUSION CODE:
<cfif Trim(seljpegPhoto) neq "">
<cftry>
<!--- upload image --->
<cffile action="upload" filefield="seljpegPhoto"
destination="#root#\update\upload" nameconflict="overwrite">
<!--- cfhttp call passes file name to update.aspx which updates the
photo --->
<cfhttp
url="#webroot#qry/update.aspx?CN=#qry_get_one_emp.cn#&photo=#file.serverfile#"
method="GET"></cfhttp>
<cfcatch type = "Any">
<cfset err = "#err#<li>There was an LDAP error updating your
image.</li><br>">
</cfcatch>
</cftry>
<!--- we print a 1 in update.aspx page if successful --->
<cfif IsDefined("cfhttp.fileContent") and Trim(cfhttp.fileContent) neq 1>
<cfset err = "#err#<li>There was an LDAP error updating your
image.</li><br>">
</cfif>
</cfif>
UPDATE.ASPX CODE:
<% @Page Language="C#" Debug="true"
CompilerOptions='/R:"c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.DirectoryServices.dll"'%>
<%@ Import Namespace="System.DirectoryServices" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
//_LDAPSERVER_ is your server and _LDAPUSERNAME_ &
_LDAPPASSWORD_ is a username/password that has rights to update the
binary attribute
System.Drawing.Image imgInFile =
System.Drawing.Image.FromFile(Server.MapPath("../update/upload/" +
Request.QueryString["photo"]));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
imgInFile.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
DirectoryEntry personInfo = new
DirectoryEntry("LDAP://_LDAPSERVER_/CN=" + Request.QueryString["CN"] +
",OU=NA,OU=Employees,O=Teleatlas,C=Global", "_LDAPUSERNAME_",
"_LDAPPASSWORD_", AuthenticationTypes.None);
try
{
personInfo.Properties["jpegPhoto"][0] = ms.ToArray();
personInfo.CommitChanges();
Response.Write ("1");
}
catch
{
Response.Write ("ERROR: Cannot find employee " +
Request.QueryString["CN"]);
ms.Close();
imgInFile = null;
Response.End();
}
ms.Close();
imgInFile = null;
}
</script>
Thanks everyone for your help on this. I'm disappointed that CF
couldn't do it. Or maybe I should reword that as "I'm disappointed I
couldn't figure out a CF-only solution".
CF Wish list: CFLDAP with a file option like...
<cfldap action="modify"
DN="#qry_get_one_emp.distinguishedName#"
attributes="jpegPhoto"
files="#file.serverfile#"
modifytype="replace"
server="#LDAPServer#"
username="#LDAPUsername#"
password="#LDAPPassword#">
At any rate, I can now move on with my development and I thank everyone
for their help on this. Especially Peter Jacoby!
-Vince
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7
The most significant release in over 10 years. Upgrade & see new features.
http://www.adobe.com/products/coldfusion?sdid=RVJR
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:273966
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4