Refresh . I found a workaround. If I send a dummy form field along with the file, it will work. Is this a ColdFusion bug, or is there something in the HTTP specification that says forms should contain at least one field without a file form?
Update 2 . I am convinced that this is cfhttp ColdFusion error. This is based on Lee's answer and on the fact that I used the code below to submit a form with only a file 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>
I have a problem downloading files from a ColdFusion server to another web server. It seems that cfhttpparam type="file" indiscriminately adds a new line (carriage return and line feed) to the end of the file. It splits binary files. This does not happen when I manually upload a file through a form field. I tried with the mimetype parameter and without it, and I tried lying about mimetype with various binary formats (exe, zip, jpg), but nothing worked. Is there any parameter that I am missing, or is this a bug in ColdFusion? (I am running CF 8.0.1.195765 on WinXP.)
Below is the test code I use, it just uploads the file to the same directory. Manual download works, but server loading ends with adding 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>
coldfusion forms file-upload
Kip
source share