2
votes

I am attempting to upload a file to the dropbox api using cfhttp. I am getting an error from Dropbox stating the Content-Type is incorrect:

Bad HTTP "Content-Type" header: "application/octet-stream,multipart/form-data; boundary=-----------------------------7d0d117230764". Expecting one of "application/octet-stream", "text/plain; charset=dropbox-cors-hack".

It appears to me that ColdFusion is appending multipart.form-data to the content type I defined in the cfhttpparam header. I am not sure how to prevent this. I am using the code below:

<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>

Any ideas on what could be going on?

1
It is probably added automatically when type="file" is used. Try sending the file binary as the request body instead, i.e. <cfhttpparam type="body" value="#FileReadBinary('C:\1_1036.gif')#">Leigh
That did it. Thank you Leigh!kpup5386
Glad it worked. I will write up an answer it case the solution helps someone else in the future.Leigh

1 Answers

1
votes

The "multipart/form-data" is probably added automatically because type="file" is used. If the API is expecting content type "application/octet-stream", that suggests it expects file data to be uploaded through the http request body, rather than as a named "file" field. Instead of type="file" try using:

<cfhttpparam type="body" value="#FileReadBinary('C:\1_1036.gif')#">