Skip to main content
Participating Frequently
January 3, 2023
Question

CF 21, cfhttp POST: body with pdf and text

  • January 3, 2023
  • 12 replies
  • 971 views

Hi.

How can I do a cfhttp POST call, to API, in CF21, with this required parmeters:

APIKEY (string) header; DOC (file pdf) formdata; TEXT (string) formdata

 

Something like this:

"

<cffile action="readBinary" file="filePathName" variable="attachedFile">

<cfset attachedFile=binaryEncode(attachedFile,"BASE64")>

<cfhttp url="#externalUrlToCall_notColdfusion#" method="POST" charset="utf-8" result="apiresult" timeout="10" multipart="yes" multipartType="form-data">

<cfhttpparam type="header" name="Content-Type" value="multipart/form-data">

<cfhttpparam type="header" name="APIKEY" value="#CONSTapiKey#">

<cfhttpparam type="header" name="Content-Disposition" value="form-data; name='DOC'; filename='fileName'">
<cfhttpparam type="formfield" name="DOC" value="#attachedFile#">
<cfhttpparam type="formfield" name="TEXT" value="Hello">
</cfhttp>
"

 

 

I'm new in API call and this don't work in CF 21 (in postman or python it works).
What am I doing wrong? Can you help me?
 
PS I saw in python that "filename='fileName'" has full path but I don't wrote it.
I solved from python but how do same API call directly from CF 21?
I upgraded from CF 18 to CF 21 and I read that this patch is embedded; it isn't?
    This topic is closed to new replies. Start a new post to keep the conversation going.

    12 replies

    Participating Frequently
    January 4, 2023

    What error or response do you actually get when doing this?

    Participating Frequently
    January 4, 2023

    400 or 500 if I try serializing fields - DOC and TEXT - in body. nothing else.

    BKBK
    Community Expert
    Community Expert
    January 4, 2023

    Example of cfhttpparam attributes for sending a PDF file:

    <cfhttpparam type="file" name="pdfFile" file="C:\Users\BKBK\Desktop\Laws of Simplicity - John Maeda.pdf" mimetype="application/pdf">