【发布时间】:2017-05-22 22:02:52
【问题描述】:
我正在尝试使用 cfhttp 将文件上传到保管箱 api。我从 Dropbox 收到一条错误消息,指出 Content-Type 不正确:
错误的 HTTP“Content-Type”标头: “应用程序/八位字节流,多部分/表单数据; 边界=--------------7d0d117230764"。期待其中之一 "application/octet-stream", "text/plain; charset=dropbox-cors-hack"。
在我看来,ColdFusion 正在将 multipart.form-data 附加到我在 cfhttpparam 标头中定义的内容类型。我不知道如何防止这种情况。我正在使用下面的代码:
<cfhttp method="post" url="https://content.dropboxapi.com/2/files/upload" result="uploadFile" multipart="no">
<cfhttpparam type="header" name="Authorization" value="Bearer #DropboxAccessToken#">
<cfhttpparam type="header" name="Dropbox-API-Arg" value="#serializeJSON(stFields)#">
<cfhttpparam type="header" name="Dropbox-API-Select-User" value="#DropboxMemberID#">
<cfhttpparam type="header" name="Content-Type" value="application/octet-stream">
<cfhttpparam type="file" name="1_1036.gif" file="C:\1_1036.gif">
</cfhttp>
对可能发生的事情有什么想法吗?
【问题讨论】:
-
使用
type="file"时可能会自动添加。尝试将文件二进制文件作为请求正文发送,即<cfhttpparam type="body" value="#FileReadBinary('C:\1_1036.gif')#"> -
做到了。谢谢你!
-
很高兴它成功了。如果该解决方案将来可以帮助其他人,我会写一个答案。
标签: coldfusion upload dropbox-api cfhttp cfhttpparam