问题描述
我正在尝试将图像上传到共享云端硬盘中的文件夹。我设法在我的驱动器上做到了这一点,但是当我尝试在共享驱动器上做到这一点时,我收到以下错误:
{
"error": {
"code": 404,"message": "File not found: 1ZQuuXVDx3I5rs6OnH8WvbWfo6HplnfW8.","errors": [
{
"locationType": "parameter","domain": "global","reason": "notFound","location": "fileId"
}
]
}
}
这让我现在很抓狂,因为我已经多次阅读文档,但找不到解决方案。我已经在 Android 上尝试过 Retrofit
、Postman
甚至 Google 提供的 OAuth2 Playground
。
请求是这个,从OAuth2 Playground
复制粘贴:
POST /upload/drive/v3/files?uploadType=multipart HTTP/1.1
Host: www.googleapis.com
Content-length: 50295
Content-type: multipart/related; boundary="===============323232404548=="
Authorization: Bearer ya29.a0AfH6SMBHmEo0Q9-8dXhhCY7wGrTj9PsFTCd0YUdLtyGJSfdO
--===============323232404548==
Content-type: application/json
{
"supportsAllDrives": true,"driveId":"0APRAdsf3Sdfsk9PVA","name":"test.jpeg","parents":[
"1ZQuuXVDx3I5rs6OnH8WvbWfo6HplnfW8"
]
}
--===============323232404548==
Content-type: image/jpeg
究竟是什么问题?我也尝试将 driveId
和 supportsAllDrives
用于请求的标头。
非常感谢任何帮助。我关注的链接:
https://developers.google.com/drive/api/v3/manage-uploads#multipart 和 https://developers.google.com/drive/api/v3/reference/files/create
解决方法
如 document 中所示,supportsAllDrives
是查询参数。这意味着它应该包含在 URI 中,而不是包含在请求正文中。
来自:
https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart
致:
https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&supportsAllDrives=true
如果查询参数中未包含 supportsAllDrives
,则默认值为 false。这会导致您的响应显示“找不到文件”消息,因为它无法找到或访问共享驱动器。