使用cfhttp上传文件附加一个换行符(甚至在二进制文件上) [英] Uploading a file with cfhttp appends a newline (even on binary files)

查看:378
本文介绍了使用cfhttp上传文件附加一个换行符(甚至在二进制文件上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:我找到了一种解决方法。如果我提交一个虚拟表单字段与文件,它的工作原理。这是一个ColdFusion错误,或者在HTTP规范中有一些东西,说表单必须包含至少一个非文件表单字段?

Update: I've found a workaround. If I submit a dummy form field along with the file, it works. Is this a ColdFusion bug, or is there something in the HTTP spec that says forms must contain at least one non-file form field?

更新2 :我相信这是一个ColdFusion cfhttp错误。这是基于Leigh的答案和事实,我使用下面的代码提交一个表单与只有的文件元素使用javascript,它工作正常:

Update 2: I'm convinced this is a ColdFusion cfhttp bug. This is based on Leigh's answer and the fact that I used the code below to submit a form with only the file element using javascript, and it works fine:

<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服务器到另一个web服务器。看来 cfhttpparam type =file是随意地在文件末尾附加一个换行符(回车和换行符)。这是破解二进制文件。当我通过表单字段手动上传文件时,不会发生此 。我试过有和没有mimetype参数,我试着说谎关于mimetype与各种二进制格式(exe,zip,jpg),但没有什么工作。有没有一些参数我缺少,或者这是ColdFusion中的一个错误? (我在WinXP的CF 8.0.1.195765上运行。)


I'm running into a problem uploading files from a ColdFusion server to another webserver. It seems that cfhttpparam type="file" is indiscriminately appending a newline (carriage return and line feed) to the end of the file. This is breaking binary files. This does not happen when I manually upload the file via form field. I have tried with and without mimetype parameter, and I've tried lying about mimetype with various binary formats (exe, zip, jpg), but nothing has worked. Is there some parameter I'm missing, or is this a bug in ColdFusion? (I'm running on CF 8.0.1.195765 on WinXP.)

下面是我使用的测试代码,它只是将文件上传到同一个目录。

Below is test code I'm using, it just uploads the file to the same directory. The manual upload works, but the server-based upload ends up appending a CRLF to the file.

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


推荐答案


在HTTP规范
中,表单必须至少包含
一个非文件表单字段?

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

不知道一定。但根据这些定义,它似乎只包含文件输入的POST应该有效。所以我怀疑这个问题可能是CFHTTP在ACF。

I do not know for certain. But according to these definitions it seems like a POST containing only a file input should be valid. So I suspect the problem may be CFHTTP in ACF.

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

According to Fiddler the raw content from the cfhttp call in ACF contains an extra new line just before the end boundary (0D 0A in hex view). But under Railo it does not. So I think ACF's cfhttp might be the culprit.

示例代码

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

这篇关于使用cfhttp上传文件附加一个换行符(甚至在二进制文件上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆