我正在尝试使用google api explorer首先尝试将对象插入谷歌云存储。
请求看起来像
POST https://www.googleapis.com/storage/v1/b/visionapibucket/o?key={YOUR_API_KEY}
{
"contentType": "image/jpeg",
"uploadType": "media",
"path": "/upload/storage/v1/b/visionapibucket/o"
}
但我将错误视为
400 HTTP/2.0 400
- Show headers -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Required"
},
{
"domain": "global",
"reason": "wrongUrlForUpload",
"message": "Upload requests must include an uploadType URL parameter and a URL path beginning with /upload/",
"extendedHelp": "https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload"
}
],
"code": 400,
"message": "Required"
}
}
不确定我错过了什么。请指教
答案 0 :(得分:1)
看起来像网站上的错误。看起来探险家似乎不支持媒体。
它生成的请求如下:
POST https://www.googleapis.com/storage/v1/b/visionapibucket/o?key={YOUR_API_KEY}
但正确的上传请求如下:
POST https://www.googleapis.com/upload/storage/v1/b/visionapibucket/o?key={YOUR_API_KEY}&uploadType=media&name=myfile.jpeg
您还需要包含“Content-Type”标头,指定它是JPEG图像。
这里有a guide on the various ways to upload objects使用JSON API。您要查找的具体类型类似于simple upload。