cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right 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: 

Corrupt file when transferring

Corrupt file when transferring

TalesDragon
Explorer | Level 3
Hello,

follow my code below:


***

Taux_API_Arg  = '{'
Taux_API_Arg += '"path":"/codechain/extrato.pdf",'
Taux_API_Arg += '"mode":"overwrite",'
Taux_API_Arg += '"autorename":true,'
Taux_API_Arg += '"mute":false'
Taux_API_Arg += '}'

cBuff := FileStr("C:\Onedrive\fontes\ManagerDropbox\extrato.pdf")
cEncBuff := hb_Base64Encode( cBuff, Len( cBuff ) )

oHttp := CreateObject("MSXML2.ServerXMLHTTP.6.0")
oHttp:Open("POST", "https://content.dropboxapi.com/2/files/upload", .f.)
oHttp:setRequestHeader("Authorization","Bearer " + alltrim(Taux_Token) )
oHttp:setRequestHeader("Content-Type", "application/octet-stream")
oHttp:setRequestHeader("Dropbox-API-Arg", Taux_API_Arg )
oHttp:Send(cEncBuff)  

***


The file is transferred to the Dropbox repository, but with a larger size, therefore corrupted !!

Original size: 58.28 Kb
Size after download: 77.44 Kb

PS: Transferring by POSTMAN, works correctly.

Grateful 
1 Reply 1

Greg-DB
Dropbox Staff

The /2/files/upload endpoint is a "content-upload" style endpoint, meaning that it expects the raw file data to be uploaded as 'application/octet-stream' in the request body. That being the case, you should send only the file data in the request body, without any additional encoding. I see in your code, for instance, that you appear to be applying a layer of base64 encoding, via the hb_Base64Encode call. You should remove that, and make sure you're only sending the expected bytes for the file.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?