cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error In Uploading a file

Error In Uploading a file

kirantara
Explorer | Level 3

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

11 Replies 11

Greg-DB
Dropbox Staff

[ Cross-linking for reference: https://stackoverflow.com/questions/61251822/unknown-api-function-files-upload ]

 

I've posted an answer on your StackOverflow question. Hope this helps! 

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

 

kirantara
Explorer | Level 3

Thank You SIr

But Couldn't understand the issue please check my code and rectfiy the code where am wrong .

 

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

ctoken := "eHiSS5jXq0AAAAAAAAAAduAlRf3zXNAV8zYWtxxxxxxxxxxxxxx"



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

oHTTP := CREATEOBJECT('Msxml2.ServerXMLHTTP.6.0')
oHTTP:OPEN("POST", url , .F.)
oHTTP:setRequestHeader("Authorization: Bearer " + ctoken)
oHTTP:setRequestHeader("Dropbox-API-Arg:")
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 help me to solve this issuse 

 

Thank you

Vikram

 

Greg-DB
Dropbox Staff

We're happy to help with any questions or issues you might have about the Dropbox API itself, but we can't debug or write code for you, especially when you're using a client not made or supported by Dropbox (in this case, oHTTP). You'll need to refer to the Dropbox API documentation for information on what formats and parameters to use when calling the Dropbox API, and then write the code for your library/platform accordingly. I also recommend referring to the documentation for your library/platform as a reference for how to construct the HTTPS requests as needed.

 

Looking at your latest code though, a few more things I notice:

  • Your cJSON begins with '{c:\tmp\pdf\CKF1907319.pdf,', but per the /2/files/upload interface, that should be more like: '{"path": "/CKF1907319.pdf",'. That's supposed to be the path on Dropbox where you want to put the uploaded file.
  • You're not actually setting anything in the "Dropbox-API-Arg" header. That should be set with your API call parameters, which you have in cJSON.
  • I don't see where you actually send the file data to upload in the request body. Perhaps that should be done in oHTTP:SEND?

kirantara
Explorer | Level 3

Hello Sir 

Could Not able to  Understand what to pass the values in cJson  and dropbox-Api-Arg    i am getting some errors please help me to solve this issue 

File Which i have to upload   is   c:\Tmp\Pdf\Email.pdf      

and want to dropbox in Folder Names   Abc2020  . how to pass both path in Cjson  and Dropbox-Api-arg   

 

This Is my code 

 

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

ctoken := "eHiSS5jXq0AAAAAAAAAAduAlRf3zXNAV8zYWtJ1xxxxxxxxxxxxxxxxxxxxxx"

cJSON := '{\"C:\TMP\PDF\EMAIL.PDF","mode": "add","autorename": true,"mute": false,"strict_conflict": false}'
url := 'https://content.dropboxapi.com/2/files/upload'
// cJSON := '{"path"\cPath, "mode": "add","autorename": true,"mute": false,"strict_conflict": false,}'

oHTTP := CREATEOBJECT('Msxml2.ServerXMLHTTP.6.0')
oHTTP:OPEN("POST", url , .F.)
oHttp:setRequestHeader( "Authorization", "Bearer " + ctoken )
 oHttp:setRequestHeader( "Dropbox-API-Arg", '{ "path": "' + cPath + '", "mode" : "add" }' )
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

 

 

Sir My Question is what to pass in Cjson and  

what to pass in Request header . 

 oHttp:setRequestHeader( "Dropbox-API-Arg", '{ "path": "' + cPath + '", "mode" : "add" }' )

 

Thanks & Regard 

Vikram Chhajer

Greg-DB
Dropbox Staff

The value you pass in the "Dropbox-API-Arg" header should be a JSON string containing the parameters you want to use for the /2/files/upload call. You can find information on each of the parameters here:

 

https://www.dropbox.com/developers/documentation/http/documentation#files-upload

 

I do recommend using a JSON library to build your JSON string instead of trying to construct it manually.

 

The API v2 Explorer may also be a useful tool for prototyping calls and seeing what they would look like:

 

https://dropbox.github.io/dropbox-api-v2-explorer/#files_upload

kirantara
Explorer | Level 3

Thank You Sir 

Cani Get Your Whatsapp number so can call You And try to understand the soultion  . If Your dont Mind sir. 

 

Thank You 

Vikram

Greg-DB
Dropbox Staff

We're not currently set up to provide API support over the phone or chat, but I'm happy to help here in the forum. 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    kirantara Explorer | Level 3
What do Dropbox user levels mean?