gpt4 book ai didi

forms - 使用 cfhttp 上传文件会附加换行符(即使在二进制文件上)

转载 作者:行者123 更新时间:2023-12-04 15:04:30 26 4
gpt4 key购买 nike

更新 : 我找到了解决方法。如果我与文件一起提交一个虚拟表单字段,它就可以工作。这是一个 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>

我在将文件从 ColdFusion 服务器上传到另一个网络服务器时遇到问题。看来 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>

最佳答案

or is there something in the HTTP spec that says forms must contain at least one non-file form field?



我不确定。但据 these definitions似乎只包含文件输入的 POST 应该是有效的。所以我怀疑问题可能是 ACF 中的 CFHTTP。

根据 Fiddler ACF 中 cfhttp 调用的原始内容在结束边界之前包含一个额外的新行(十六进制 View 中的 0D 0A)。但在 Railo 下则不然。所以我认为 ACF 的 cfhttp 可能是罪魁祸首。

示例代码:
<cfhttp url="http://127.0.0.1:8888/cfusion/receive.cfm" method="post">
<cfhttpparam name="myFile" type="file" file="c:/test/testFile.zip" mimetype="application/octet-stream" />
</cfhttp>

结果 Railo 3.1.2
POST /railo/receive.cfm HTTP/1.1
User-Agent: Railo (CFML Engine)
Host: 127.0.0.1:8888
Content-Length: 382
Content-Type: multipart/form-data; boundary=m_l7PD5xIydR_hQpo8fDxL0Hb7vu_F8DSzwn

--m_l7PD5xIydR_hQpo8fDxL0Hb7vu_F8DSzwn
Content-Disposition: form-data; name="myFile"; filename="testFile.zip"
Content-Type: application/octet-stream; charset=ISO-8859-1
Content-Transfer-Encoding: binary

PK
&�1=�cN'testFile.txtTestingPK
&�1=�cN' testFile.txtPK:1
--m_l7PD5xIydR_hQpo8fDxL0Hb7vu_F8DSzwn--

结果 ACF(版本 8 和 9)
POST /cfusion/receive.cfm HTTP/1.1
Host: 127.0.0.1:8888
... other headers removed for brevity ....
Content-type: multipart/form-data; boundary=-----------------------------7d0d117230764
Content-length: 350

-------------------------------7d0d117230764
Content-Disposition: form-data; name="JobFile"; filename="c:\test\testFile.zip"
Content-Type: application/octet-stream

PK
&�1=�cN'testFile.txtTestingPK
&�1=�cN' testFile.txtPK:1

-------------------------------7d0d117230764--

关于forms - 使用 cfhttp 上传文件会附加换行符(即使在二进制文件上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3738580/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com