[英]How to perform a multipart upload with Google Drive REST API v3
我正在嘗試按照指南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
我需要設置正確的正文長度,否則服務器返回錯誤。
用戶更新就是答案
好的,經過幾次嘗試,我找到了正確的 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
我需要設置正確的正文長度,否則服務器返回錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.