Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using cfhttp, copied file is appended and original is overwritten

Guest
Mar 09, 2011 Mar 09, 2011

I'm not sure if its the cfhttp configuration or if this is a problem with the webdav server configuration.

Here's my CF code:

  <cftry>
        <cfhttp  method="put" url="https://#Application.psupload.Webdavserver##Application.psupload.Filetxt#" username="clb39" password="5wimF1shco" throwonerror="yes" path="#Application.psupload.Pathtxt#" multipart="Yes" timeout="30000">
            <cfhttpparam type="file" name="#Application.psupload.Filetxt#" file="#Application.psupload.Pathtxt##Application.psupload.Filetxt#">
        </cfhttp>
        <cfset Application.psupload.msg="#Application.psupload.msg# Webdav Success<br>">
        <cfcatch>
            <cfset Application.psupload.msg="#Application.psupload.msg# Webdav Failure<br>">
        </cfcatch>
    </cftry>

It looks like a 'return code' that overwrites the original file:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>201 Created</title>
</head><body>
<h1>Created</h1>
<p>Resource /[removed]/Upload_1103080403.txt has been created.</p>
<hr />
<address>Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.7d DAV/2 Server at [removed] Port 8[removed]0</address>
</body></html>

The copied file is made correctly, but some how 4 lines are added, and the 3rd one has this string each time:

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

Any thoughts? Is it cfhttp or Webdav?

TIA,

CB

876
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 11, 2011 Apr 11, 2011
LATEST

The end result was bad coding. The proper format:

        <cfhttp  method="put" url="https://#Application.psupload.Webdavserver##Application.psupload.Filetxt#" username="*" password="**************" throwonerror="yes">
            <cfhttpparam type="file" name="#Application.psupload.Filetxt#" file="#Application.psupload.Pathtxt##Application.psupload.Filetxt#" mimetype="text/plain">
        </cfhttp>

The original code was wrong b/c:

  1. path="#Application.psupload.Pathtxt#" - should be the return message path, ie log of transaction. By setting it equeal to the file to be copied, it gets overwritten.

I did run into an additional issue creating the export file with an extra carriage return and line being added to the end of the file - this was a problem with cfloop and was resolved by 2 cfloop statements to the file, first writing queryrecords-1 and second just writing the last record in query without a new line

Sample Code:

<cftry>
                <cfloop query="Pending" startrow="1" endrow="#(Pending.recordcount)-1#>
                    <cffile action="append"
                    file="#Application.psupload.Pathtxt##Application.psupload.Filetxt#"
                    output="#TRIM(UniqueAppID)#--- cut for clarity"                
                    addnewline="yes">
                </cfloop>
                <cfset Application.psupload.msg="#Application.psupload.msg# multi Local txt File populated sucessfully<br>">
                    <cftry>
                        <cfloop query="Pending" startrow="#pending.recordcount#" endrow="#pending.recordcount#">
                            <cffile action="append"
                                 file="#Application.psupload.Pathtxt##Application.psupload.Filetxt#"
                                 output="#TRIM(UniqueAppID)#-- cut for clarity"                
                                 addnewline="no">
                            </cfloop>
                        <cfset Application.psupload.msg="#Application.psupload.msg# multi Local txt File completed sucessfully<br>">
                            <cfcatch>
                                <cfset Application.psupload.msg="#Application.psupload.msg# multi Local txt File Last record Failed<BR>">
                            </cfcatch>
                    </cftry>
                           
                <cfcatch>
                    <cfset Application.psupload.msg="#Application.psupload.msg# multi Local txt File population Failed<BR>">
                </cfcatch>
            </cftry>

Doing this mean I also need to control for when Pending has only 1 record, which other code handles.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources