Kip*_*Kip 6 forms coldfusion file-upload
更新:我找到了解决方法.如果我提交一个虚拟表单字段和文件,它可以工作.这是一个ColdFusion错误,还是HTTP规范中有些内容表明表单必须包含至少一个非文件表单字段?
更新2:我确信这是一个ColdFusion cfhttp错误.这是基于Leigh的答案以及我使用下面的代码使用javascript 仅使用文件元素提交表单的事实,并且它工作正常:
<form enctype="multipart/form-data" action="<cfoutput>#CGI.PATH_INFO#</cfoutput>" method="POST" name="theForm">
<input name="theFile" type="file" /><br/>
</form>
<a href="#" onclick="document.theForm.submit()">submit</a>
Run Code Online (Sandbox Code Playgroud)
我在将文件从ColdFusion服务器上传到另一个Web服务器时遇到了问题.似乎cfhttpparam type="file"是不加选择地在文件末尾添加换行符(回车符和换行符).这打破了二进制文件.这不,当我手动上传通过表单字段的文件发生.我尝试过有和没有mimetype参数,我试过用各种二进制格式(exe,zip,jpg)说谎mimetype,但没有任何效果.是否有一些我缺少的参数,或者这是ColdFusion中的一个错误?(我在WinXP上运行CF 8.0.1.195765.)
下面是我正在使用的测试代码,它只是将文件上传到同一目录.手动上载有效,但基于服务器的上载最终会将CRLF附加到文件中.
<cfset MyDir = "C:\test" />
<cfset MyFile = "test.zip" />
<cfif IsDefined("Form.TheFile")>
<cffile action="upload" fileField="theFile" destination="#MyDir#" nameConflict="MakeUnique" />
<cfelse>
<cfhttp url="http://#CGI.SERVER_NAME##CGI.SCRIPT_NAME#" method="POST" throwOnError="Yes">
<cfhttpparam type="file" name="theFile" file="#MyDir#\#MyFile#" />
</cfhttp>
</cfif>
<html><body>
<h2>Manual upload</h2>
<form enctype="multipart/form-data" action="<cfoutput>#CGI.PATH_INFO#</cfoutput>" method="POST">
<input name="theFile" type="file" /><br/>
<input type="submit" value="Submit" />
</form>
</body></html>
Run Code Online (Sandbox Code Playgroud)
\n\n\n或者 HTTP 规范中是否有规定表单必须至少包含一个非文件表单字段?
\n
我不确定。但根据这些定义,似乎只包含文件输入的 POST 应该是有效的。所以我怀疑问题可能出在ACF中的CFHTTP上。
\n\n根据Fiddler 的说法,ACF 中 cfhttp 调用的原始内容在结束边界之前包含一个额外的新行(十六进制视图中的 0D 0A)。但在 Railo 的统治下,情况并非如此。所以我认为 ACF 的 cfhttp 可能是罪魁祸首。
\n\n示例代码:
\n\n<cfhttp url="http://127.0.0.1:8888/cfusion/receive.cfm" method="post">\n <cfhttpparam name="myFile" type="file" file="c:/test/testFile.zip" mimetype="application/octet-stream" />\n</cfhttp>\nRun Code Online (Sandbox Code Playgroud)\n\n结果铁路 3.1.2
\n\nPOST /railo/receive.cfm HTTP/1.1\nUser-Agent: Railo (CFML Engine)\nHost: 127.0.0.1:8888\nContent-Length: 382\nContent-Type: multipart/form-data; boundary=m_l7PD5xIydR_hQpo8fDxL0Hb7vu_F8DSzwn\n\n--m_l7PD5xIydR_hQpo8fDxL0Hb7vu_F8DSzwn\nContent-Disposition: form-data; name="myFile"; filename="testFile.zip"\nContent-Type: application/octet-stream; charset=ISO-8859-1\nContent-Transfer-Encoding: binary\n\nPK\n&\xef\xbf\xbd1=\xef\xbf\xbdcN\'testFile.txtTestingPK\n&\xef\xbf\xbd1=\xef\xbf\xbdcN\' testFile.txtPK:1\n--m_l7PD5xIydR_hQpo8fDxL0Hb7vu_F8DSzwn--\nRun Code Online (Sandbox Code Playgroud)\n\n结果 ACF(版本 8 和 9)
\n\nPOST /cfusion/receive.cfm HTTP/1.1\nHost: 127.0.0.1:8888\n... other headers removed for brevity ....\nContent-type: multipart/form-data; boundary=-----------------------------7d0d117230764\nContent-length: 350\n\n-------------------------------7d0d117230764\nContent-Disposition: form-data; name="JobFile"; filename="c:\\test\\testFile.zip"\nContent-Type: application/octet-stream\n\nPK\n&\xef\xbf\xbd1=\xef\xbf\xbdcN\'testFile.txtTestingPK\n&\xef\xbf\xbd1=\xef\xbf\xbdcN\' testFile.txtPK:1\n\n-------------------------------7d0d117230764--\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
2136 次 |
| 最近记录: |