【发布时间】:2011-09-16 22:19:42
【问题描述】:
我们正在尝试与需要文件的 RESTful Web 服务进行交互。
我将字段的名称设置为 data(根据 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的类型设置为文件并使用文件属性?
标签: coldfusion