• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ColdFusion CFHTTPPARAM Content-Type?

New Here ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

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>

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

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,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

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,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

Yes, I have hit them up for advise also.  Thanks again!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

And testing by deleting

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 28, 2019 Apr 28, 2019

Copy link to clipboard

Copied

LATEST

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation