2015-10-15 29 views
0

我能夠從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#,以便能夠嘗試所有類型的變量

而且嘗試這些PARAMS:

<cfset obj.test1 = BinaryImageContent /> 
    <cfdump var="#imageGetBlob(anotherImage)#" /> 
    <cfdump var="#toString(obj.test1)#" /> 

順便說一句,我得到它的

一個或多個所需的屬性的錯誤可能丟失或不正確或 你做的不是H ave權限在服務器上執行此操作。

的問題是,我使用的域管理員帳戶來更新

(此錯誤是解決 - 網絡人員沒有給我這個權限...現在我有它)。

現在我使用的是以下幾點:

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

,但我得到這個二進制代碼

enter image description here

請告訴我奇怪的是,之前我有一個二進制代碼像-1 -41和現在,沒有什麼類似的...

當我試圖顯示圖片

enter image description here

這是一個正確的圖像.... enter image description here

回答

2

編輯:下面的原代碼示例展示瞭如何可能工作,如果ColdFusion的不會有錯誤(或者「非常不幸的設計決定「)在CFLDAP中。

CFLDAP在發送給服務器之前對傳遞給它的參數值進行編碼。這很好,因爲你不必擔心值編碼。但...它也沒有幫助,因爲它意味着你不能再發送編碼值了,因爲CF總是編碼它們再次

底線:就LDAP而言,將文件編碼爲十六進制字符串是正確的,但CFLDAP會在將該字符串發送到服務器之前對其進行修正。結合CFLDAP不接受原始二進制數據這一事實,這意味着您不能使用它來更新二進制屬性。

註釋包含一個第三方命令行工具的建議,該工具可以輕鬆地將CFLDAP替換爲此任務。


您需要將編碼字符串作爲屬性值發送到服務器。 LDAP查詢中二進制數據的編碼方案的格式爲attribute=\01\02\03\ab\af\cd

將圖像讀入字節數組,將該數組編碼爲十六進制字符串,並將每個編碼字節用反斜槓前綴。

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

而且不要忘了the documentation有什麼看法modifyType

+0

我得到這個錯誤,因爲它看起來像我發送一個數據到大值爲 嘗試執行修改時發生錯誤:[LDAP:錯誤代碼19 - 00002082:AtrErr:DSID-03151314,# 1:0:00002082:,問題1005(CONSTRAINT_ATT_TYPE),數據0,Att 160023(thumbnailPhoto):len 466635]。 –

+0

參見http://blog.cjwdev.co.uk/2010/11/03/the-thumbnailphoto-attribute-explained/。 「thumbnailPhoto」大小限制爲100 Kb,建議大小爲96 x 96像素。使用CF的照片編輯功能來製作一張真實的縮略圖。同時比較[thumbnailPhoto'上的MSDN](https://msdn.microsoft.com/en-us/library/cc221395.aspx),尤其是'rangeUpper'部分。 – Tomalak

+0

所以,實際上網絡夥計騙我,管理員用戶有權更改ldap帳戶...現在它已經和我沒有收到錯誤,我沒有權限... 無論如何,我收到奇怪的二進制,當我這樣做...將更新我的問題與數據和圖像 –