我可以将文件上传到 Google 磁盘的根目录,但不能将文件上传到子目录
I can upload files to root of the Google Disk, but can't upload file to subdirectory
我正在尝试使用 Google 驱动器 API 的基于 HTTP 的协议将文件上传到 Google 磁盘。
要求:
POST /upload/drive/v3/files?uploadType=multipart HTTP/1.1
Host: www.googleapis.com
Content-length: 317
Content-type: multipart/related; boundary="===============1113791900570109977=="
Authorization: Bearer ...
--===============1113791900570109977==
Content-type: application/json
{
"mimeType": "text/plain",
"parentID": "[\'16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI\']",
"folder": "test",
"name": "test1.txt"
}
--===============6521522044179315692==
Content-type: text/plain
test1
--===============6521522044179315692==--
回复:
HTTP/1.1 200 OK
Content-length: 119
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Vary: Origin, X-Origin
Server: UploadServer
Date: Sun, 06 Jun 2021 11:18:11 GMT
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
X-guploader-uploadid: ABg5-UxJxPPfItZVlcOjWSM74dRtuNGFN-S88K_BU9lYi9Bjz-JgU9GzUPp2ghHP83ynJKklgVtsOPaLonv1KkISPg
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"
Content-type: application/json; charset=UTF-8
{
"mimeType": "text/plain",
"kind": "drive#file",
"id": "1d_ZC7slHvidXAu774SOE_nkBuO-Bblsk",
"name": "test1.txt"
}
我添加到元数据对象,parents: ['16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI'] 其中该字符串是我要将其上传到的文件夹的 ID。但是文件总是在根目录上传。
我做错了什么?
在你的请求正文中,我认为"parentID": "[\'16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI\']",
需要修改。而且,没有 属性 of folder
。那么,下面的修改呢?
发件人:
{
"mimeType": "text/plain",
"parentID": "[\'16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI\']",
"folder": "test",
"name": "test1.txt"
}
收件人:
{
"mimeType": "text/plain",
"parents": ["16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI"],
"name": "test1.txt"
}
- 在此请求正文中,
test1.txt
的文件创建在 16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI
的文件夹中。
参考文献:
我正在尝试使用 Google 驱动器 API 的基于 HTTP 的协议将文件上传到 Google 磁盘。
要求:
POST /upload/drive/v3/files?uploadType=multipart HTTP/1.1
Host: www.googleapis.com
Content-length: 317
Content-type: multipart/related; boundary="===============1113791900570109977=="
Authorization: Bearer ...
--===============1113791900570109977==
Content-type: application/json
{
"mimeType": "text/plain",
"parentID": "[\'16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI\']",
"folder": "test",
"name": "test1.txt"
}
--===============6521522044179315692==
Content-type: text/plain
test1
--===============6521522044179315692==--
回复:
HTTP/1.1 200 OK
Content-length: 119
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Vary: Origin, X-Origin
Server: UploadServer
Date: Sun, 06 Jun 2021 11:18:11 GMT
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
X-guploader-uploadid: ABg5-UxJxPPfItZVlcOjWSM74dRtuNGFN-S88K_BU9lYi9Bjz-JgU9GzUPp2ghHP83ynJKklgVtsOPaLonv1KkISPg
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"
Content-type: application/json; charset=UTF-8
{
"mimeType": "text/plain",
"kind": "drive#file",
"id": "1d_ZC7slHvidXAu774SOE_nkBuO-Bblsk",
"name": "test1.txt"
}
我添加到元数据对象,parents: ['16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI'] 其中该字符串是我要将其上传到的文件夹的 ID。但是文件总是在根目录上传。
我做错了什么?
在你的请求正文中,我认为"parentID": "[\'16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI\']",
需要修改。而且,没有 属性 of folder
。那么,下面的修改呢?
发件人:
{
"mimeType": "text/plain",
"parentID": "[\'16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI\']",
"folder": "test",
"name": "test1.txt"
}
收件人:
{
"mimeType": "text/plain",
"parents": ["16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI"],
"name": "test1.txt"
}
- 在此请求正文中,
test1.txt
的文件创建在16zJngsKtpLtlFe-WTo8LOCCQ2k-uqkZI
的文件夹中。