用于将文件上传到我的保管箱的malformed_pa​​th

时间:2017-06-29 07:47:47

标签: bash curl dropbox

本地spurce文件:/tmp/back/wp.bak.sql
Dst文件:/
我的访问令牌是xxxxxx 我想将本地电脑上的/tmp/back/wp.bak.sql上传到dropbox根目录,并保持名称不变。

curl命令1:

curl -X POST  https://content.dropboxapi.com/2/files/upload \
  --header 'Authorization: Bearer xxxxxx' \
  --header 'Content-Type: application/octet-stream' \
  --header 'Dropbox-API-Arg: {"path":"/"}' \
  --data-binary @'/tmp/back/wp.bak.sql' 

输出信息。

{"error_summary": "path/malformed_path/...", "error": {".tag": "path", "reason": {".tag": "malformed_path"}, "upload_session_id": ""}}

curl命令2:

cd /tmp/back
curl -X POST  https://content.dropboxapi.com/2/files/upload \
  --header 'Authorization: Bearer xxxxxx' \
  --header 'Content-Type: application/octet-stream' \
  --header 'Dropbox-API-Arg: {"path":"/"}' \
  --data-binary @'wp.bak.sql' 

相同的错误信息。 如何修复curl命令的malformed_pa​​th?

2 个答案:

答案 0 :(得分:2)

path字段中输入文件的完整路径:

--header 'Dropbox-API-Arg: {"path":"/wp.bak.sql"}'

所以:

curl "https://content.dropboxapi.com/2/files/upload" \
  -H 'Authorization: Bearer xxxxxx' \
  -H 'Content-Type: application/octet-stream' \
  -H 'Dropbox-API-Arg: {"path":"/wp.bak.sql"}' \
  --data-binary @'wp.bak.sql' 

答案 1 :(得分:0)

此问题之前的答案已过时且无效。这是一个经过测试和完美运行的工作代码

curl -X POST https://content.dropboxapi.com/2/files/upload \
  --header "Authorization: Bearer <your token>" \
  --header "Dropbox-API-Arg: {\"path\": \"/file_path.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}" \
  --header "Content-Type: application/octet-stream" \
  --data-binary "@file_path.txt"