我使用以下代码成功连接到版本1:
<cfhttp method="post"
url="http://do.convertapi.com/Word2Pdf"
result="convertAttempt"
path="#arguments.path#"
file="#arguments.fileToDestination#"
>
<cfhttpparam type="formfield" name="ApiKey" value="xxxxxxx" >
<cfhttpparam type="file" file="#arguments.path#/#arguments.fileToConvert#" name="File" >
</cfhttp>下面是我尝试用于version 2的代码。它将一个文件写入正确的文件夹,但它不是一个可读的PDF。我认为这与base64有关,但不确定。不管怎样,希望有另一个ColdFusion用户能帮我。然后,我们希望在convertAPI站点上获得代码示例,以帮助其他人。
<cfhttp method="post"
url="http://v2.convertapi.com/docx/to/pdf?Secret=mysecret"
result="convertAttempt"
path="#arguments.path#"
file="#arguments.fileToDestination#"
>
<cfhttpparam type="file" file="#arguments.path##arguments.fileToConvert#" name="File" >
</cfhttp>发布于 2018-04-04 16:06:55
默认情况下,JSONVersion2返回ConvertAPI。您需要使用Base64解码器对文件进行解码。
为了节省响应时间和带宽,最好将accept=application/octet-stream头部添加到请求中,以获得即时的二进制响应,而无需任何解码。
发布于 2018-04-04 23:47:02
使用注释和Tomas's answer中的建议,以下是我的最终代码。它首先反序列化来自JSON的响应。然后将来自base64的pdf解码为二进制。最后,将二进制pdf文件保存到磁盘。
<cfhttp method="post" url="http://v2.convertapi.com/docx/to/pdf?Secret=your-secret" result="convertAttempt">
<cfhttpparam type="file" file="#arguments.path##arguments.fileToConvert#" name="File" >
</cfhttp>
<cfset FileResult = deserializeJSON(convertAttempt.FileContent) />
<cfif isDefined("fileResult.Code")>
<!--- Failed --->
<cfelse>
<cfset FileWrite("#arguments.path##arguments.fileToDestination#", BinaryDecode(FileResult.Files[1].FileData, "base64"))>
</cfif>https://stackoverflow.com/questions/49641167
复制相似问题