如何使用 cfldap 更改用户图像?
How to change the user image using cfldap?
我能够从 cfldap 获得我想要的所有值。
但是当我尝试更新用户图像时,我不知道如何为二进制图像属性发送正确的值。
我尝试从 cffile 上传中获取图像变量
<cffile action="UPLOAD" filefield="file" destination="c:\inetpub\wwwroot\test" nameconflict="OVERWRITE" result="image" />
还尝试将 cfimage 与静态图像一起使用 -
<cfimage action="read" source="c:\inetpub\wwwroot\test\image.png" name="anotherImage">
甚至
<cffile action="READBINARY" file="c:\inetpub\wwwroot\test\image.png" variable="BinaryImageContent">
但无论如何,当我打电话时
<cfldap action="modify"
DN="#results.dn#"
attributes="thumbnailPhoto=#obj.image#"
modifytype="replace"
server="myserver"
username="mydomain\myuser"
password="mypass">
#results.dn# 是我之前从用户那里得到的 DN(一切正常)
我创建了#obj.image# 以便能够尝试所有类型的变量
还尝试了这些参数:
<cfset obj.test1 = BinaryImageContent />
<cfdump var="#imageGetBlob(anotherImage)#" />
<cfdump var="#toString(obj.test1)#" />
对了,我得到它的错误
One or more of the required attributes may be missing or incorrect or
you do not have permissions to execute this operation on the server.
问题是我正在使用域管理员帐户更新
(此错误已解决 - 网络人员没有给我此权限...现在我有了)。
现在我使用的是:
<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, "..", "\[=15=]", "ALL")>
<cfldap
action="modify"
DN="#results.dn#"
attributes="thumbnailPhoto=#imgStr2#"
modifytype="replace"
server="myserver"
username="mydomain\myuser"
password="mypass"
>
但我得到了这个二进制代码
奇怪的是,之前我有一个像 -1-41 这样的二进制代码,现在没有类似的东西了...
当我尝试显示图片时
这是一张正确的图片....
编辑:下面的原始代码示例显示了如果 ColdFusion 没有错误(或 "very unfortunate design decision") 在 CFLDAP 中。
CFLDAP 在将您传递给它的参数值发送到服务器之前对其进行编码。这很好,因为您不必担心值编码。但是......它也没有帮助,因为这意味着你不能再自己发送编码值,因为 CF 总是对它们进行编码 again.
底线:就 LDAP 而言,将文件编码为十六进制字符串是正确的,但 CFLDAP 在将该字符串发送到服务器之前对其进行了处理。结合 CFLDAP 不接受原始二进制数据的事实,这意味着您不能使用它来更新二进制属性。
评论包含对第 3 方命令行工具的建议,该工具可以轻松替代 CFLDAP 来完成此任务。
您需要将编码后的字符串作为属性值发送到服务器。 LDAP 查询中二进制数据的编码方案具有 attribute=\ab\af\cd
.
的形式
将图像读入字节数组,将该数组编码为十六进制字符串,并在每个编码字节前加上反斜杠。
<cffile action="readbinary" file="#filename#" variable="img">
<cfset imgStr = BinaryEncode(img, "hex")>
<cfset imgStr = REReplace(imgStr, "..", "\[=10=]", "ALL")>
<cfldap
action="modify"
DN="#results.dn#"
attributes="thumbnailPhoto=#imgStr#"
modifytype="replace"
server="myserver"
username="mydomain\myuser"
password="mypass"
>
也不要忘记 the documentation 对 modifyType
的看法。
我能够从 cfldap 获得我想要的所有值。 但是当我尝试更新用户图像时,我不知道如何为二进制图像属性发送正确的值。
我尝试从 cffile 上传中获取图像变量
<cffile action="UPLOAD" filefield="file" destination="c:\inetpub\wwwroot\test" nameconflict="OVERWRITE" result="image" />
还尝试将 cfimage 与静态图像一起使用 -
<cfimage action="read" source="c:\inetpub\wwwroot\test\image.png" name="anotherImage">
甚至
<cffile action="READBINARY" file="c:\inetpub\wwwroot\test\image.png" variable="BinaryImageContent">
但无论如何,当我打电话时
<cfldap action="modify"
DN="#results.dn#"
attributes="thumbnailPhoto=#obj.image#"
modifytype="replace"
server="myserver"
username="mydomain\myuser"
password="mypass">
#results.dn# 是我之前从用户那里得到的 DN(一切正常) 我创建了#obj.image# 以便能够尝试所有类型的变量
还尝试了这些参数:
<cfset obj.test1 = BinaryImageContent />
<cfdump var="#imageGetBlob(anotherImage)#" />
<cfdump var="#toString(obj.test1)#" />
对了,我得到它的错误
One or more of the required attributes may be missing or incorrect or you do not have permissions to execute this operation on the server.
问题是我正在使用域管理员帐户更新
(此错误已解决 - 网络人员没有给我此权限...现在我有了)。
现在我使用的是:
<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, "..", "\[=15=]", "ALL")>
<cfldap
action="modify"
DN="#results.dn#"
attributes="thumbnailPhoto=#imgStr2#"
modifytype="replace"
server="myserver"
username="mydomain\myuser"
password="mypass"
>
但我得到了这个二进制代码
奇怪的是,之前我有一个像 -1-41 这样的二进制代码,现在没有类似的东西了...
当我尝试显示图片时
这是一张正确的图片....
编辑:下面的原始代码示例显示了如果 ColdFusion 没有错误(或 "very unfortunate design decision") 在 CFLDAP 中。
CFLDAP 在将您传递给它的参数值发送到服务器之前对其进行编码。这很好,因为您不必担心值编码。但是......它也没有帮助,因为这意味着你不能再自己发送编码值,因为 CF 总是对它们进行编码 again.
底线:就 LDAP 而言,将文件编码为十六进制字符串是正确的,但 CFLDAP 在将该字符串发送到服务器之前对其进行了处理。结合 CFLDAP 不接受原始二进制数据的事实,这意味着您不能使用它来更新二进制属性。
评论包含对第 3 方命令行工具的建议,该工具可以轻松替代 CFLDAP 来完成此任务。
您需要将编码后的字符串作为属性值发送到服务器。 LDAP 查询中二进制数据的编码方案具有 attribute=\ab\af\cd
.
将图像读入字节数组,将该数组编码为十六进制字符串,并在每个编码字节前加上反斜杠。
<cffile action="readbinary" file="#filename#" variable="img">
<cfset imgStr = BinaryEncode(img, "hex")>
<cfset imgStr = REReplace(imgStr, "..", "\[=10=]", "ALL")>
<cfldap
action="modify"
DN="#results.dn#"
attributes="thumbnailPhoto=#imgStr#"
modifytype="replace"
server="myserver"
username="mydomain\myuser"
password="mypass"
>
也不要忘记 the documentation 对 modifyType
的看法。