Skip to main content
Participating Frequently
May 23, 2017
Question

ColdFusion CFHTTPPARAM Content-Type?

  • May 23, 2017
  • 3 replies
  • 1811 views

I am attempting to upload a file using the Dropbox API.  Dropbox requires Contact-Type = "application/octet-stream", which I am tried to set in the cfhttpparam type = "header".  However when I post the data to the API.  I get an error stating: Bad HTTP "Content-Type" header: "application/octet-stream,multipart/form-data; boundary=-----------------------------7d0d117230764".  I am guessing that when a cfhttpparam type = "file" is included, the content-type is modified to also include multipart/form-data.  The api will not accept this content-type.  Is there a way to avoid this behavior?  This is the code I am using to attempt the upload.  Thank you.

<cfhttp method="post" url="https://content.dropboxapi.com/2/files/upload" result="uploadFile">

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

This topic has been closed for replies.

3 replies

New Participant
April 28, 2019

Hello ,

I could upload files to DropBox using this code, You can check and please tell the results.

You need to send data in JSON format for "DropBox-API-Arg" header so first we will create it.

I used API key instead of OAuth credentials. It also can handle any errors and send you the error details.

I uploaded a ZIP file so please bear in mind that you need to change the extension of file if you want to upload different file type with different extension.

<cfoutput>

<cfset PathOfLocalFile = "The PATH TO YOUR FILE THAT WANT TO UPLOAD" />

<cfset DropBoxPath = "/THE-FOLDER-PATH-IN-DROPBOX/FILENAME.zip" />

<cfset APIKEY = YOURAPIKEYHERE />

<cfset ToEmail = YOUREMAILADDRESSHERE />

<cfset FromEmail = YOURFROMEMAILADDRESSHERE />

<cfset DBArg = #SerializeJson({

    "path": "#DropBoxPath#",

    "mode": "add",

    "autorename": true,

    "mute": false,

    "strict_conflict": false

})#  />

<cftry>

                              

<cfhttp url="https://content.dropboxapi.com/2/files/upload" timeout="150" charset="utf-8" method="post" throwonerror="yes" >

<cfhttpparam name="Content-Type" value="application/octet-stream" type="header">

<cfhttpparam type="header" name="Authorization" value=" Bearer #APIKEY#" >

<cfhttpparam type="header" name="Dropbox-API-Arg" value="#DBArg#" >

<cfhttpparam type="file" file="#PathOfLocalFile#" name="--data-binary">

</cfhttp>

   <cfcatch type="any">

<cfmail to="#ToEmail#" from="#FromEmail#" charset="utf-8" type="html" subject="Error: in send files to DropBox #DateTimeFormat (Now(), "MM-dd-HH:nn:ss")#" >

          Error occured...<br /><br />

        Message: <b>#cfcatch.Message#</b><br />

        Detail: <b>#cfcatch.Detail#</b><br />

        Type: <b>#cfcatch.Type#</b><br />

        <cfdump var="#cfcatch#" ><br />

        <cfdump var="#cfhttp.FileContent#" />

</cfmail>

  

   </cfcatch>

 

</cftry>

</cfoutput>

BKBK
Braniac
May 23, 2017

You could test by disabling the multipart attribute in cfhttp, like this

<cfhttp method="post" url="https://content.dropboxapi.com/2/files/upload" result="uploadFile" multipart="no">

EBG1103Author
Participating Frequently
May 23, 2017

Thank you.  I did try that.  Did not appear to have any effect on the content type sent to the API.  

BKBK
Braniac
May 24, 2017

And testing by deleting

<cfhttpparam type="header" name="Content-Type" value="application/octet-stream"> ?

WolfShade
Braniac
May 23, 2017

Hello, EBG1103​,

I deleted my Dropbox account over security concerns, and have never attempted to try to get Dropbox to work with CF.  However, a quick Google search did bring up a few items of interest.  One of those is dropboxCFC on riaforge.net.  It might contain code that could help you with your uploading issue.

HTH,

^_^

EBG1103Author
Participating Frequently
May 23, 2017

Thank you!  I have looked at that in the past.  Unfortunately, it is coded for a deprecated version of the core api. I am convinced ColdFusion is appending a value to the content-type.  I am trying to find out if I can override that behavior so it only passes application/octet-stream in the content-type.

WolfShade
Braniac
May 23, 2017

Have you utilized the developers section of Dropbox?

https://www.dropbox.com/developers might have some answers, for you.  I would check, myself, but the FQDN is blocked by proxy, here.

HTH,

^_^