【问题标题】:How to perform a multipart upload with Google Drive REST API v3如何使用 Google Drive REST API v3 执行分段上传
【发布时间】:2021-02-10 08:43:05
【问题描述】:

我正在尝试按照指南 https://developers.google.com/drive/api/v3/manage-uploads#multipart 发出 https 请求以上传文件。这是我尝试发送的内容:

POST https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&key=AIz...Q4 HTTP/1.1\r\n
Authorization: Bearer ya...8A\r\n
Content-Type: multipart/related; boundary=foo_bar_baz\r\n
Content-Length: 150\r\n
\r\n
--foo_bar_baz\n
Content-Type: application/json; charset=UTF-8\n
\n
{\n
    "title": "My File.jpg"\n
}\n
\n
--foo_bar_baz\n
Content-Type: text/txt\n
\n
JPEG data\n
--foo_bar_baz--\r\n

你能告诉我我错了什么或一个可行的例子吗?谢谢

更新:

好的,经过几次尝试我都能找到正确的https请求,例如:

POST https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&key=AI...qeQ4 HTTP/1.1\r\n
Authorization: Bearer yaSN...Q9Q\r\n
Content-Type: multipart/related; boundary=foo_bar_baz\r\n
Content-Length: 167\r\n
\r\n
--foo_bar_baz\n
Content-Type: application/json; charset=UTF-8\n
\n
{\n
    "name": "My File.txt"\n
}\n
--foo_bar_baz\n
Content-Type: text/plain; charset=UTF-8\n
\n
aaaaa\n
--foo_bar_baz--

回复:

HTTP/1.1 200 OK\r\n
X-GUploader-UploadID: ABg...lRCA\r\n
Vary: Origin\r\n
Vary: X-Origin\r\n
Content-Type: application/json; charset=UTF-8\r\n
Cache-Control: no-cache, no-store, max-age=0, must-revalidate\r\n
Pragma: no-cache\r\n
Expires: Mon, 01 Jan 1990 00:00:00 GMT\r\n
Date: Thu, 11 Feb 2021 17:37:39 GMT\r\n
Content-Length: 121\r\n
Server: UploadServer\r\n
Alt-Svc: h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"\r\n
\r\n
{\n
 "kind": "drive#file",\n
 "id": "1_SE...8X",\n
 "name": "My File.txt",\n
 "mimeType": "text/plain"\n
}\n

我需要设置正确的body长度,否则服务器会返回错误。

【问题讨论】:

  • 您发送的内容会怎样?你有错误信息吗?我们不提供示例,我们可以帮助您解决问题。
  • 感谢您的回复。服务器回复我:HTTP/1.1 400 Bad Request ... Missing end boundary in multipart body.HTTP/1.0 400 Bad Request ... 您的客户端发出了格式错误或非法的请求...
  • 您能否分享有关错误的更多信息以及您如何处理请求?
  • 感谢您的回答。我已经分享了更多信息!
  • 请更新第一个问题,不要添加更新作为答案,这可能会使其他有相同或类似问题的用户感到困惑。

标签: arduino google-api google-drive-api


【解决方案1】:

用户更新就是答案

好的,经过几次尝试我都能找到正确的https请求,例如:

POST https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&key=AI...qeQ4 HTTP/1.1\r\n
Authorization: Bearer yaSN...Q9Q\r\n
Content-Type: multipart/related; boundary=foo_bar_baz\r\n
Content-Length: 167\r\n
\r\n
--foo_bar_baz\n
Content-Type: application/json; charset=UTF-8\n
\n
{\n
    "name": "My File.txt"\n
}\n
--foo_bar_baz\n
Content-Type: text/plain; charset=UTF-8\n
\n
aaaaa\n
--foo_bar_baz--

回复:

HTTP/1.1 200 OK\r\n
X-GUploader-UploadID: ABg...lRCA\r\n
Vary: Origin\r\n
Vary: X-Origin\r\n
Content-Type: application/json; charset=UTF-8\r\n
Cache-Control: no-cache, no-store, max-age=0, must-revalidate\r\n
Pragma: no-cache\r\n
Expires: Mon, 01 Jan 1990 00:00:00 GMT\r\n
Date: Thu, 11 Feb 2021 17:37:39 GMT\r\n
Content-Length: 121\r\n
Server: UploadServer\r\n
Alt-Svc: h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"\r\n
\r\n
{\n
 "kind": "drive#file",\n
 "id": "1_SE...8X",\n
 "name": "My File.txt",\n
 "mimeType": "text/plain"\n
}\n

需要设置正确的body长度,否则服务器返回错误。

【讨论】:

    猜你喜欢
    • 2021-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多