指定要使用 Google 云存储通知发布的元数据
Specifying Metadata to publish with Google Cloud Storage Notifications
我在 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'
你可以多看看'readably'here
但是,this documentation guide 暗示我们可以 trim 深入到我们感兴趣的特定元数据。例如,文件名 "objectId"。但它并没有确切说明如何通过 gsutil 实现这一点。在上面的文字墙中,还有"timeCreated"和"size".
我想设置一个通知,将上传的文件的名称作为 MESSAGE 输出,并将创建时间和大小作为属性输出。
谁能解释一下如何操纵输入代码来实现这一点?
无法将负载更改为仅包含字段的子集。如果您为 payloadFormat
.
指定 JSON_API_V1
,则通知负载始终包含完整的对象元数据
唯一的选择是将 payloadFormat
设置为 NONE
。这将根本不发送有效负载,但您仍然可以从通知的 attributes 中额外获取一些信息。对于您的用例,属性包含 objectId
,但不包含 size
和 timeCreated
。对于那些额外的字段,您需要阅读完整的有效负载。
要使用 gsutil 指定无负载,请使用 -f none
选项。详情见:
https://cloud.google.com/storage/docs/gsutil/commands/notification#options
我在 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'
你可以多看看'readably'here
但是,this documentation guide 暗示我们可以 trim 深入到我们感兴趣的特定元数据。例如,文件名 "objectId"。但它并没有确切说明如何通过 gsutil 实现这一点。在上面的文字墙中,还有"timeCreated"和"size".
我想设置一个通知,将上传的文件的名称作为 MESSAGE 输出,并将创建时间和大小作为属性输出。
谁能解释一下如何操纵输入代码来实现这一点?
无法将负载更改为仅包含字段的子集。如果您为 payloadFormat
.
JSON_API_V1
,则通知负载始终包含完整的对象元数据
唯一的选择是将 payloadFormat
设置为 NONE
。这将根本不发送有效负载,但您仍然可以从通知的 attributes 中额外获取一些信息。对于您的用例,属性包含 objectId
,但不包含 size
和 timeCreated
。对于那些额外的字段,您需要阅读完整的有效负载。
要使用 gsutil 指定无负载,请使用 -f none
选项。详情见:
https://cloud.google.com/storage/docs/gsutil/commands/notification#options