I recently wanted to download and upload files from my Dropbox. Turns out that this is easy to do in Tcl.
If all you need is access to your own Dropbox, you don't have to implement the authorization process. Instead:
You need HTTP and TLS:
package require http package require tls http::register https 443 ::tls::socket
To download a file, note its filename within your Dropbox root folder. Prefix it with "https://api-content.dropbox.com/1/files/auto ". Here, I download the default file "How to use the Public folder.txt" from my Public directory. Note that the file name must be URL-encoded.
set access_token "<copy and paste from above>" set file "/Public/How%20to%20use%20the%20Public%20folder.txt" set base "https://api-content.dropbox.com/1/files/auto" set url "${base}${file}" set headers [list Host api-content.dropbox.com Authorization "Bearer $access_token"]
Now just use the http command to download the file:
set token [http::geturl $url -headers $headers] http::wait $token
Get the file content with http::data $token.
File upload is nearly as simple:
set access_token "<copy and paste from above>" set base "https://api-content.dropbox.com/1/files_put/auto" set url "${base}${file}" set content "<file contents>" set contentLength [string length $content] set contentType "application/binary" set access_token "<copy and paste from above>" set headers [list Content-Length $contentLength Host api-content.dropbox.com Authorization "Bearer $access_token"] set token [http::geturl $url -headers $headers -method PUT -type $contentType -query $content] http::wait $token