GCP 存储 - 如何在可恢复上传中设置自定义元数据?

GCP Storage - How to set custom metadata in resumable upload?

我正在使用存储 JSON api。

编辑得更具体:

当我:

POST https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=resumable HTTP/1.1
Authorization: Bearer [MY_AUTH_TOKEN]
Content-Length: 38
Content-Type: application/json; charset=UTF-8
X-Upload-Content-Type: image/jpeg
X-Upload-Content-Length: 2000000

{ "name": "myObject", "foo":  "bar" }

然后只设置文件名,我想在 metadata 字段中看到 "foo" : "bar"


documentation中:

(1)

The /upload URI, for the media. The format of the /upload endpoint is the standard resource URI with an /upload prefix. Use this URI when transferring the media data itself. Example: POST /upload/storage/v1/b/myBucket/o.

(2)

The standard resource URI, for the metadata. If the resource contains any data fields, those fields are used to store metadata describing the uploaded file. You can use this URI when creating or updating metadata values. Example: POST /storage/v1/b/myBucket/o.

他们还举了一个 /upload (1) 请求的例子:

If you have metadata for the file, add the metadata to the request body in JSON format. Otherwise, leave the request body empty.

有点矛盾

尽管如此,将 json 正文发送到 /upload :仅设置 'name' 属性有效。

向元数据请求发送相同的 json 正文让我得到:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "wrongUrlForUpload",
    "message": "Upload requests must include an uploadType URL parameter and a URL path beginning with /upload/",
...

谢谢! :)

编辑:这主要是将该文件分配给它所属的任何人并验证哈希值,我完全可以使用图像的 name 来解决这个问题。

要在通过 JSON API 上传的对象上设置自定义元数据,请使用这种消息正文:

{"name": "myObject", "metadata": {"foo": "bar"}}