首页 > 解决方案 > 如何将 ReportCloud API 响应返回到可下载文件中?

问题描述

我正在使用 ColdFusion 调用ReportCloud API,它根据我通过 cfhttp 发送的参数即时合并邮件。

文档的回复说:

成功时,响应标头中的 HTTP 状态代码为 200(OK)。响应正文包含编码为 Base64 编码字符串的已创建文档数组。

有人可以帮助我如何将该响应转换为可下载文件,无论是链接还是直接下载?我可能应该知道这一点,但不幸的是我不知道。

添加评论:

感谢您对这个问题的帮助和指导。我第一次使用 StackOverflow 作为海报,如果问题含糊,我深表歉意。

我还整理了一个代码示例来查看cffiddle

<!--- Must replace "Authorization" header below with a real key --->
<cfset variables.jsonReq = '{
    "mergeData": [
        {
            "Given_Name": "Mike",
            "Surname": "Smith",
            "Year_Group": "11"
         },
         {
            "Given_Name": "Sally",
            "Surname": "Smith",
            "Year_Group": "12"
         }
    ],
    "template": null,
    "mergeSettings": null
    }'>

<cfhttp url="https://api.reporting.cloud/v1/document/merge?returnFormat=DOC&templateName=parentletter.docx" method="post" timeout="20" result="response" file="/www/something.docx">
    <cfhttpparam type="header" name="Content-Type" value="application/json">
    <cfhttpparam type="header" name="Authorization" value="ReportingCloud-APIKey oMDM4MrAqL9QEOpyzupnQW5NjvCNtvE5cVDaaLqxI">
    <cfhttpparam type="body" name="mergeData" value="#jsonReq#">
</cfhttp>

<cfdump var="#response#">

响应以我认为是 JSON 数组的形式返回。我不确定如何读取该 JSON 数组并将内容制作成可下载的文件。

标签: coldfusion

解决方案


推荐阅读