我們正在嘗試與期望文件的RESTful Web服務進行交互。如何獲得帶有文件參數的CFHTTP以僅顯示文件名而不是完整路徑?
我將該字段的名稱設置爲數據(根據API的要求),然後將該文件指定爲絕對路徑。當文件傳遞給服務器時,HTTP事務中的文件名就是完整的絕對路徑。
這會導致API出現問題,因爲完整路徑會被記錄爲「文件名」。
如何讓ColdFusion只報告文件名而不是完整路徑?
我們使用ColdFusion 9
這裏是CFML:
<cfhttp url="http://server/testcode"
port="9876"
method="post"
result="Content">
<cfhttpparam type="file"
name="data"
file="c:\temp\testfile.txt">
</cfhttp>
這裏有不同的瀏覽器的HTTP交互的一些例子:
CFHTTP 9
-------------------------------7d0d117230764
Content-Disposition: form-data; name="data"; filename="c:\temp\testfile.txt"
Content-Type: text/plain
This is the text, really long, well, not really.
-------------------------------7d0d117230764--
IE8
-----------------------------7db370d80e0a
Content-Disposition: form-data; name="FileField"; filename="C:\temp\testfile.txt"
Content-Type: text/plain
This is the text, really long, well, not really.
-----------------------------7db370d80e0a--
Chrome 13
------WebKitFormBoundaryDnpFVJwCsZkzTGDc
Content-Disposition: form-data; name="FileField"; filename="testfile.txt"
Content-Type: text/plain
This is the text, really long, well, not really.
Firefox 6
-----------------------------22798303036224
Content-Disposition: form-data; name="FileField"; filename="testfile.txt"
Content-Type: text/plain
This is the text, really long, well, not really.
-----------------------------22798303036224--
顯然IE8和CFHTTP都做同樣的事情(將「c:\ temp」添加到文件名中)。我不確定HTTP的規範是什麼,但如果有辦法讓CFHTTP離開這條路,那將會很不錯。
有沒有辦法做到這一點?
你可以發表一些代碼,我不確定要理解...... API的期望類型的數據(二進制,字符串)? –
您是否將「httpparam」的類型設置爲文件並使用文件屬性? –