【问题标题】:Specifying Metadata to publish with Google Cloud Storage Notifications指定要使用 Google Cloud Storage 通知发布的元数据
【发布时间】:2019-05-14 08:30:29
【问题描述】:

this thread 的帮助下,我已经开始使用 gsutil 命令:

gsutil notification create \
-t bucketcfpubsub -f json \
-e OBJECT_FINALIZE gs://bucketcfpubsub

我通过它发布了这条消息:

b'{\n "kind": "storage#object",\n "id": "bucketcfpubsub/test.txt/1544681756538155",\n "selfLink": "https://www.googleapis.com/storage/v1/b/bucketcfpubsub/o/test.txt",\n "name": "test.txt",\n "bucket": "bucketcfpubsub",\n "generation": "1544681756538155",\n "metageneration": "1",\n "contentType": "text/plain",\n "timeCreated": "2018-12-13T06:15:56.537Z",\n "updated": "2018-12-13T06:15:56.537Z",\n "storageClass": "STANDARD",\n "timeStorageClassUpdated": "2018-12-13T06:15:56.537Z",\n "size": "1938",\n "md5Hash": "sDSXIvkR/PBg4mHyIUIvww==",\n "mediaLink": "https://www.googleapis.com/download/storage/v1/b/bucketcfpubsub/o/test.txt?generation=1544681756538155&alt=media",\n "crc32c": "UDhyzw==",\n "etag": "CKvqjvuTnN8CEAE="\n}\n'

你可以看到它更“可读”here

但是,this documentation guide 暗示我们可以将其缩减为我们感兴趣的特定元数据。例如,带有“objectId”的文件名。但它并没有确切说明如何通过 gsutil 实现这一点。在上面的文字墙中,还有“timeCreated”和“size”。

我想设置一个通知,将上传的文件名作为 MESSAGE 输出,并将 timeCreated 和 size 作为属性输出。

谁能解释一下如何操纵输入代码来实现这一点?

【问题讨论】:

    标签: google-cloud-platform google-cloud-storage google-cloud-pubsub gsutil


    【解决方案1】:

    无法将有效负载更改为仅包含字段的子集。如果您为payloadFormat 指定JSON_API_V1,则通知负载始终包含完整的对象元数据。

    唯一的选择是将payloadFormat 设置为NONE。这根本不会发送任何有效负载,但您仍然可以从通知的attributes 中额外提供一些信息。对于您的用例,属性包含objectId,但不包含sizetimeCreated。对于这些附加字段,您需要阅读完整的有效负载。

    要使用 gsutil 指定无负载,请使用 -f none 选项。详情见: https://cloud.google.com/storage/docs/gsutil/commands/notification#options

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-26
      • 2017-11-23
      • 2020-09-26
      • 2019-08-22
      相关资源
      最近更新 更多