Chuanyie Lim
Chuanyie Lim

Reputation: 31

Decode file content

im working on a project which send a file to client side through api. i use the PUT method to send the file but getting 400 bad request. after checking the log, found that all my file content has been endoded. but when i download the file, its content still look ok. may i know how to send the file and make sure the file content is decoded? Below is part of my code.

actually i do have this code before call the api, not sure whether is it bcoz of this code affect the filecontent become encoded..

<cffile action="write" nameconflict="overwrite" file="#filename#" output="#toString(invoiceXML)#">
<cfhttp url="#requestUrl#" method="PUT" result="res" throwonerror="yes">
    <cfhttpparam name="Authorization" type="header" value="Basic #token#">
    <cfhttpparam name="Content-Type" type="header" value="multipart/form-data">
    <cfhttpparam type="file" name="document" file="#filename#" >
</cfhttp>

enter image description here

Upvotes: 3

Views: 524

Answers (1)

steve
steve

Reputation: 70

According to the reference for cfhttpparam the file shouldn't get URL-Encoded. Are you sure the encoding happens in the code snippet you posted?

If the reference is actually wrong and the file is getting encoded by the cfhttpparam you could try adding the encoded attribute:

<cfhttp url="#requestUrl#" method="PUT" result="res" throwonerror="yes">
    <cfhttpparam name="Authorization" type="header" value="Basic #token#">
    <cfhttpparam name="Authorization" type="header" value="Basic #token#">
    <cfhttpparam name="Content-Type" type="header" value="multipart/form-data">
    <cfhttpparam type="file" name="document" file="#filename#" encoded="no">
</cfhttp>

If the file contents are already encoded, you could try the URLDecode function to decode it.

Upvotes: 2

Related Questions