Forum Discussion

kirantara's avatar
kirantara
Explorer | Level 3
5 years ago

Error In Uploading a file

Hello Experts 

I am New To Dropbox Api And Today i was trying to uplaod a file from api but got error .  

 

Unknown API function: "files/upload \\eHiSS5jxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

i am using Http api  and my code is 

 

function main()
local oHTTP,cJSON,url
setmode(25,80)

ctoken := "<REDACTED>"

url := "https://content.dropboxapi.com/2/files/upload \" + ctoken
cJSON := '{"c:\tmp\pdf\CKF1907319.pdf","mode": "add","autorename": true,"mute": false,"strict_conflict": false,}'
URL
? cjson
wt = inkey(0)

oHTTP := CREATEOBJECT('Msxml2.ServerXMLHTTP.6.0')
oHTTP:OPEN("POST", url , .F.)
oHTTP:setRequestHeader("Content-Type", "application/octet-stream")
oHTTP:SEND(cJSON)
IF oHTTP:status != 200
? oHTTP:responseText
hb_memowrit("response.txt",oHTTP:responseText)
? "Error"
ELSE
? oHTTP:responseText
hb_memowrit("response.txt",oHTTP:responseText)
ENDIF
wt = inkey(0)
return  

 

Please me to solve this issue

 

Vikram

    • kirantara's avatar
      kirantara
      Explorer | Level 3

      Thank For your reply 

       

      But After Change the url as you suggested i got same error 

      Unknown API function: "files/upload \\Authorization:eHiSS5jXq0AAAAAAAAAAduAlRf3zXNAV8zYWtJ12Iirzoxxxxxxxxxxx".

       

      function main()
      local oHTTP,cJSON,url
      setmode(25,80)

      ctoken := "eHiSS5jXq0AAAAAAAAAAduAlRf3zXNAV8zYWtJ1xxxxxxxxxxxxxxxxx"

      * // cJSON = {"path": "hb_cwd()+"report.txt","mode": "add","autorename": true,"mute": false,"strict_conflict": false"}



      url := "https://content.dropboxapi.com/2/files/upload \" + "Authorization:" + ctoken
      cJSON := '{"c:\tmp\pdf\CKF1907319.pdf","mode": "add","autorename": true,"mute": false,"strict_conflict": false,}'

      ? URL
      ? cjson
      wt = inkey(0)

      oHTTP := CREATEOBJECT('Msxml2.ServerXMLHTTP.6.0')
      oHTTP:OPEN("POST", url , .F.)
      oHTTP:setRequestHeader("Content-Type", "application/octet-stream")
      oHTTP:SEND(cJSON)
      IF oHTTP:status != 200
      ? oHTTP:responseText
      hb_memowrit("response.txt",oHTTP:responseText)
      ? "Error"
      ELSE
      ? oHTTP:responseText
      hb_memowrit("response.txt",oHTTP:responseText)
      ENDIF
      wt = inkey(0)
      return

       

      please give example in http format how the api link look like 

      https://content.dropboxapi.com/2/files/upload \Authorization:eHiSS5jXq0AAAAAAAAA
      AduAlRf3zXNAV8zYWtJ12IirzonOa58ixxxxxxxxxxx 
      {"c:\tmp\pdf\CKF1907319.pdf","mode": "add","autorename": true,"mute": false,"str
      ict_conflict": false,}

       

      Please help to issue the error

      Thank You 

      Vikram

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        In this code, you're still putting the access token on the URL, but additionally with the string "Authorization". You should instead be sending this as a header. Based on the rest of your code, for your client that would probably look something like this:

         

        oHTTP:setRequestHeader("Authorization", "Bearer" + ctoken)

        Likewise, note that for /2/files/upload, the API call parameters (your cJSON), should go in a "Dropbox-API-Arg" header, and the file data to upload should go in the request body. Please refer to the /2/files/upload documentation for more information on how to properly format this API call.