coldfusion - How to change the user image using cfldap? -
i'm able values want cfldap. when try update user image don't know how send correct value binary image attribute.
i tried getting image variable cffile upload
<cffile action="upload" filefield="file" destination="c:\inetpub\wwwroot\test" nameconflict="overwrite" result="image" />
also tried using cfimage static image -
<cfimage action="read" source="c:\inetpub\wwwroot\test\image.png" name="anotherimage">
or
<cffile action="readbinary" file="c:\inetpub\wwwroot\test\image.png" variable="binaryimagecontent">
but in case, when call
<cfldap action="modify" dn="#results.dn#" attributes="thumbnailphoto=#obj.image#" modifytype="replace" server="myserver" username="mydomain\myuser" password="mypass">
the #results.dn# dn user before (everything ok on that) created #obj.image# able try types of variables
also tried these params:
<cfset obj.test1 = binaryimagecontent /> <cfdump var="#imagegetblob(anotherimage)#" /> <cfdump var="#tostring(obj.test1)#" />
by way, error its
one or more of required attributes may missing or incorrect or not have permissions execute operation on server.
the problem i'm using domain administrator account update that
(this error solved - network guys hadn't given me permission... have it).
now i'm using following:
<cffile action="upload" filefield="file" destination="c:\inetpub\wwwroot\test" nameconflict="overwrite" result="imagem" /> <cfset filename = "c:\inetpub\wwwroot\test\#imagem.serverfile#"> <cffile action="readbinary" file="#filename#" variable="img"> <cfset imgstr = binaryencode(img, "hex")> <cfset imgstr2 = rereplace(imgstr, "..", "\\\0", "all")> <cfldap action="modify" dn="#results.dn#" attributes="thumbnailphoto=#imgstr2#" modifytype="replace" server="myserver" username="mydomain\myuser" password="mypass" >
but binary code
whats strange, before had binary code -1-41 , now, nothing similar...
and when try show pic
edit: original code sample below shows how could work if coldfusion wouldn't have bug (or "very unfortunate design decision") in cfldap.
cfldap encodes parameter values pass before sending them server. nice because don't have worry value encoding. but... not helpful because means can't send encoded values anymore, since cf invariably encodes them again.
bottom line: far ldap concerned, encoding file hex-string correct, cfldap mangles string before sending server. combined fact cfldap not accept raw binary data means can't use update binary attributes.
the comments contain suggestion 3rd-party command line tool can substitute cfldap task.
you need send encoded string server attribute value. encoding scheme binary data in ldap queries has form of attribute=\01\02\03\ab\af\cd
.
read image byte array, encode array hex string , prefix every encoded byte backslash.
<cffile action="readbinary" file="#filename#" variable="img"> <cfset imgstr = binaryencode(img, "hex")> <cfset imgstr = rereplace(imgstr, "..", "\\\0", "all")> <cfldap action="modify" dn="#results.dn#" attributes="thumbnailphoto=#imgstr#" modifytype="replace" server="myserver" username="mydomain\myuser" password="mypass" >
also don't forget the documentation has modifytype
.
Comments
Post a Comment