通过 Dropbox Api 和 curl 上传 zip 文件

Upload zip file via Dropbox Api and curl

我正在尝试使用

上传 .zip 文件

卷曲请求:

curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer <Access Token>" \
--header "Dropbox-API-Arg: {\"path\": \"/upload.zip\"}" \
--header "Content-Type: application/octet-stream" \
--data-binary @/upload.zip

上传完成,没有错误。从另一台设备(Ubuntu 服务器)下载也已完成。但是当我尝试解压缩时,出现以下错误:

Archive:  upload.zip
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in one of upload.zip or
        upload.zip.zip, and cannot find upload.zip.ZIP, period.

我猜我的 curl 上传配置有问题。可能有一些特殊的配置来上传和下载 .zip 文件。

我做错了什么?如何通过 Dropbox api 以正确的方式上传 .zip 文件?

一天后我发现了问题所在。 由于大多数不工作的情况,你必须检查你的代码和语法...

1) 文件路径应在引号内:

--data-binary @"/upload.zip"

2) 下载路径以斜杠开头:

curl -X POST https://content.dropboxapi.com/2/files/download \
    --header "Authorization: Bearer <Token>" \
    --header "Dropbox-API-Arg: {\"path\": \"/directory/upload.zip\"}" >>upload.zip

一般来说,检查下载的 zip 文件是否具有正确的文件大小是个好主意。如果文件大小与本地存储中的文件大小不同,则上传未成功完成。