ColdFusion cfhttp looses metadata in uploading docx file

I am having a problem uploading a docx file. It looses 2 bytes after I upload and save it to the server. Here is my code.

<cffunction name="akamaiUpload" access="private" output="false">
    <cfargument name="filename" type="string" required="true">
    <cfargument name="localpath" type="string" required="true">

    <cftry>

        <cfhttp url="http://sample.com/#arguments.filename#" method="post">
            <cfhttpparam type="file" name="user_file" file="#arguments.localpath#" />
        </cfhttp>

    <!--- catch any error, return the error message --->
    <cfcatch type="any">
        <cfreturn #cfcatch.message#>
    </cfcatch>

    </cftry>
</cffunction>

I've found some code with the same issue and tried to apply their solution but still it didn't work. Here is the code.

<cffunction name="akamaiUpload" access="private" output="false">
    <cfargument name="filename" type="string" required="true">
    <cfargument name="localpath" type="string" required="true">

    <cffile action="readbinary" file="#arguments.localpath#" variable="myfile">
        <cfset by=CreateObject("java","java.lang.String")>
        <cfset by.init(myfile, "iso-8859-1")>
        <cfset contentdivider=Hash("this is my divider for this")>

        <cfhttp method="POST" url="http://sample.com/#arguments.filename#" charset="iso-8859-1">
            <cfhttpparam type="header" name="Content-Type" value="multipart/form-data; boundary=#contentDivider#">
            <cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
            <cfhttpparam type="Header" name="TE" value="deflate;q=0">
        </cfhttp>       

    <!--- returning true for successful upload --->
    <cfreturn true>
</cffunction>

Has anyone here experienced the same issue? Please share some suggestions.

链接地址: http://www.djcxy.com/p/5286.html

上一篇: ColdFusion CFHTTP和SSL Certs

下一篇: ColdFusion cfhttp在上传docx文件时丢失了元数据